替代方法
- (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的一个错误,所以顺势找一个替代方法,实现条条大路通罗马,凡事都不能一棵树上吊死。