iOS 數(shù)組--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循環(huán)

}

}

asdf++;

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

}

iOS 數(shù)組--objectAtIndex的方法用于獲取數(shù)組中的元素在數(shù)組中的下表,至于為什么我找一個(gè)替代方法是因?yàn)榻裉煸赬code7.3.1上面真機(jī)調(diào)試,一直抱這樣的錯,而且還導(dǎo)致程序崩潰,錯誤信息: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è)錯誤,所以順勢找一個(gè)替代方法,實(shí)現(xiàn)條條大路通羅馬,凡事都不能一棵樹上吊死。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容