iOS 数组--objectAtIndex

替代方法

- (void)viewDidLoad {

[super viewDidLoad];

asdf = 0;

UIButton* but =[UIButton buttonWithType:UIButtonTypeContactAdd];

[self.view addSubview:but];

but.frame = CGRectMake(80, 120, 30, 30);

[but addTarget:self action:@selector(didTap:) forControlEvents:UIControlEventTouchUpInside];

}

- (void)didTap:(UIButton*)but{

NSArray* arr =@[@"2014",@"2015",@"2016"];

self.ast = arr;

NSInteger index;

for (int i = 0; i < arr.count; i++) {

if ([[NSString stringWithFormat:arr[asdf]] isEqualToString:arr[i]]) {

index = i;

break;//跳出for循环

}

}

asdf++;

NSLog(@"%ld",(long)index);

}

iOS 数组--objectAtIndex的方法用于获取数组中的元素在数组中的下表,至于为什么我找一个替代方法是因为今天在Xcode7.3.1上面真机调试,一直抱这样的错,而且还导致程序崩溃,错误信息:warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.。经查,这可能是Xcode7.3.1的一个错误,所以顺势找一个替代方法,实现条条大路通罗马,凡事都不能一棵树上吊死。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容