ios - 数组项在 IOS 中显示错误

标签 ios objective-c arrays

我有一个包含一些项目的数组,用于在单击按钮时旋转 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
}
}

错误在这里: enter image description here

最佳答案

您已将 cureentIndex 声明为 NSString *,因此当您说 person[cureentIndex] 时,编译器认为 person 必须是一个字典,因为您正在使用对象的 [] 访问。这会导致错误,因为 person 实际上是一个数组,它不能用字符串索引。

我认为您是想将 cureentIndex 声明为 int,或者您可能是想说 currentIndex

关于ios - 数组项在 IOS 中显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46846806/

相关文章:

ios - 哪些 iOS 设备具有接近监控功能?

ios - 从另一个 UIViewController 刷新表格

ios - 如果应用程序处于非事件状态,AFNetWorking 在 30 秒后执行 setCompletionBlock

javascript - 在Javascript中使用Symbol.iterable进行迭代时如何检测当前元素是最后一个元素?

c++ - 对于二维矩阵,它在 C++11 中是否与 C11 中的函数类似?

ios - 单击tableview Cell中的Collectionview时如何找到tableview的索引路径

ios - 从按钮的操作方法调用时 PrepareForSegue 不起作用 (Swift)

objective-c - 图片不想拖

iphone - Objective-C 是创建 iphone 应用程序的强制性要求吗?

c++ - 解码字符数组