请考虑以下代码:
-(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(), ^{
当然,如果没有 promise ,通过定时器调用函数当然是不好的。为什么调用委托(delegate)方法会导致崩溃?如何在不使用 dispatch_after 调用的情况下避免它?
最佳答案
NEVER EVER 直接调用以 will
、should
和 did
开头或包括在内的委托(delegate)方法。它们仅由目标类调用。
要选择一行,UITableView
类中有一个方法
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath
animated:(BOOL)animated
scrollPosition:(UITableViewScrollPosition)scrollPosition
关于ios - 选择表中的行导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572910/