次のコードをifステートメントからswitchステートメントに変更しようとしましたが、idオブジェクトではなく整数が必要であるというエラーが表示されます。
これが私のスイッチです:
-(void) nearestIndexAfterRotationEnded:(int)index {
NSLog(@"Selected item is: %@", [colorNames objectAtIndex:index]);
statusLabel.text = [NSString stringWithFormat:@"Selected item is: %@", [colorNames objectAtIndex:index]];
switch ([colorNames objectAtIndex:])) {
case 1:
[redButton setImage:[UIImage imageNamed:@"Btn1_1.png"] forState:UIControlStateNormal];
break;
case 2:
[redButton setImage:[UIImage imageNamed:@"Btn1_2.png"] forState:UIControlStateNormal];
break;
default:
break;
}
そして、これが私のif条件文です:
-(void) nearestIndexAfterRotationEnded:(int)index {
NSLog(@"Selected item is: %@", [colorNames objectAtIndex:index]);
statusLabel.text = [NSString stringWithFormat:@"Selected item is: %@", [colorNames objectAtIndex:index]];
if ([colorNames objectAtIndex:0]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_1.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:1]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_2.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:2]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_3.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:3]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_4.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:4]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_5.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:5]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_6.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:6]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_7.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:7]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_8.png"] forState:UIControlStateNormal];
}
if ([colorNames objectAtIndex:8]) {
[redButton setImage:[UIImage imageNamed:@"Btn1_9.png"] forState:UIControlStateNormal];
}
}
助けてくれてありがとう