我有一个带有复选标记附件的长列表的设置页面。用户可以选择任意数量的行,我将它们保存在 NSUserDefaults 中。我希望下次他们打开设置时选择他们以前的选择,所以我尝试了这个:
NSArray *array = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"choices"]];
if (array.count !=0) {
NSLog(@"not empt");
for (id obj in array) {
NSIndexPath *path = [NSIndexPath indexPathWithIndex:obj];
[self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionTop];
}
}
但是应用程序每次都会因此错误而崩溃:
erminating 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.
我究竟做错了什么?谢谢