我在使用发布配置运行时遇到了错误,这似乎是局部变量的过早发布tmp
。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.'
相关代码:
@property (nonatomic, strong) NSIndexPath *selectedCellIndexPath;
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_selectedCellIndexPath != nil && [_selectedCellIndexPath isEqual:indexPath]) {
self.selectedCellIndexPath = nil;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (_selectedCellIndexPath != nil && ![_selectedCellIndexPath isEqual:indexPath]) {
//--- problematic code
NSIndexPath *tmp = _selectedCellIndexPath;
self.selectedCellIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:@[tmp, _selectedCellIndexPath] withRowAnimation:UITableViewRowAnimationFade];
//--- problematic code
} else {
self.selectedCellIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我的印象是局部变量tmp
在这里应该有很强的引用,或者我不对?
顺便说一句,将代码更改为
NSIndexPath *tmp = self.selectedCellIndexPath;
或者改变
@[tmp, _selectedCellIndexPath]
解决[NSArray arrayWithObjects:tmp,_selectedCellIndexPath,nil]
问题。
这里出了什么问题的解释是什么?