The*_*0s3 1 objective-c uitableview ios
我有一个方法,旨在清除所有UITableViewCellAccessories,并在调用时收到以下错误
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.'
这是方法
-(void)clearTableViewAccessories{
NSIndexPath *indexPath = [NSIndexPath new];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
Run Code Online (Sandbox Code Playgroud)
初始化indexPath对象的方式是,创建一个长度为0且没有路径的索引路径,该路径由一个部分和一个行组成.
您应该使用指定的初始化程序创建indexPath
indexPathForRow:inSection:
无论如何,我不认为您的实施是解决问题的最佳方式.使用当前设置,您需要为要创建的每个单元格创建一个indexPath,并且对于任何不可见的单元格,您将获得nil.
最好的事情是开始查看UITableView dataSource方法,首先是tableView:cellForRowAtIndexPath:并在这里决定是否清理单元格.
| 归档时间: |
|
| 查看次数: |
5184 次 |
| 最近记录: |