請考慮下面的代碼:選擇行表導致死機
-(void)selectSpecificRowForSpotlight:(NSNumber*)row{
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
/* Fill news list */
if (self.singlObj.getSpotlightArray.count > 1){
if (self.viewModel.arrValues.count > 1){
NSLog(@"we got spotlight");
[self.viewModel.arrValues insertObject:[[self.singlObj.spotArray objectAtIndex:self.singlObj.currentSpotlightIndex-1] objectAtIndex:0] atIndex:0];
[self.viewModel.arrValues insertObject:[[self.singlObj.spotArray objectAtIndex:self.singlObj.currentSpotlightIndex-1] objectAtIndex:1] atIndex:1];
[self.viewModel.arrValues insertObject:[[self.singlObj.spotArray objectAtIndex:self.singlObj.currentSpotlightIndex-1] objectAtIndex:2] atIndex:2];
}
}
[self.myTableView reloadData];
});
NSIndexPath *path = [NSIndexPath indexPathForRow:[row integerValue] inSection:0];
[self.myTableView.delegate tableView:self.myTableView didSelectRowAtIndexPath:path];
}
細節都無所謂,問題是,下面幾行:
NSIndexPath *path = [NSIndexPath indexPathForRow:[row integerValue] inSection:0];
[self.myTableView.delegate tableView:self.myTableView didSelectRowAtIndexPath:path];
原因的死機(SIGABRT錯誤)。我修復它:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
但當然,它是不好的,由計時器調用一個函數,沒有承諾。爲什麼調用委託方法會導致崩潰?如何避免使用dispatch_after調用?
@vadian如果我需要選擇特定的行修改數值數組後有什麼方法? –