我有一个包含一些项目的数组,用于在单击按钮时旋转 ImageView ,现在当我传递数组并获取当前索引时它显示错误,我很困惑为什么我会得到这个。 我的代码是这样的:
- (IBAction)my:(id)sender {
NSString *cureentIndex=0;
NSArray *persons = [NSArray arrayWithObjects:@"M_PI",@" M_PI_4",@" M_PI_2",@"M_PI*2", nil];
NSArray *person = @[@"M_PI", @"M_PI_4", @"M_PI_2"];
_imageView.transform = CGAffineTransformMakeRotation(person[cureentIndex])
if currentIndex != persons.count-1 {
currentIndex = currentIndex + 1
}else {
// reset the current index back to zero
currentIndex = 0
}
}
最佳答案
您已将 cureentIndex
声明为 NSString *
,因此当您说 person[cureentIndex]
时,编译器认为 person
必须是一个字典,因为您正在使用对象的 []
访问。这会导致错误,因为 person
实际上是一个数组,它不能用字符串索引。
我认为您是想将 cureentIndex
声明为 int
,或者您可能是想说 currentIndex
?
关于ios - 数组项在 IOS 中显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46846806/