Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 选择viewdidload上已保存的选中标记行_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 选择viewdidload上已保存的选中标记行

Ios 选择viewdidload上已保存的选中标记行,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有一个设置页面,其中有一个带有复选标记附件的长列表。用户可以选择任意多的行,我让他们保存在NSUserDefaults中。我希望下次打开“设置”时选择他们以前的选择,因此我尝试了以下方法: NSArray *array = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"choices"]]; if (array.count !=0) { NSLog(@"not

我有一个设置页面,其中有一个带有复选标记附件的长列表。用户可以选择任意多的行,我让他们保存在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.

我做错了什么?谢谢

这个错误很容易解释。UIKit中的nsindexpath需要两个索引,一个用于节,一个用于行。它是

假设表视图中只有一个部分:

for (id obj in array) {
    NSIndexPath *path = [NSIndexPath indexPathForRow:obj inSection:0];
    [self.tableView selectRowAtIndexPath:path animated:NO scrollPosition:UITableViewScrollPositionTop];
}

现在获取此-[UITableView\u ContentOffsetForScrollingToRowatineXPath:atScrollPosition:]:行(204883856)超出节(0)的边界(10)。'