替代方法
- (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循環(huán)
}
}
asdf++;
NSLog(@"%ld",(long)index);
}
iOS 數(shù)組--objectAtIndex的方法用于獲取數(shù)組中的元素在數(shù)組中的下表截汪,至于為什么我找一個(gè)替代方法是因?yàn)榻裉煸赬code7.3.1上面真機(jī)調(diào)試,一直抱這樣的錯(cuò)匾浪,而且還導(dǎo)致程序崩潰科平,錯(cuò)誤信息:warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.颖杏。經(jīng)查,這可能是Xcode7.3.1的一個(gè)錯(cuò)誤,所以順勢找一個(gè)替代方法,實(shí)現(xiàn)條條大路通羅馬挪凑,凡事都不能一棵樹上吊死。