0
for(NSUInteger j = 0 ; j < [sports count] ; j++){

    NSIndexPath *loopPath = [NSIndexPath indexPathWithIndex:j]; 

    if([pickerTable cellForRowAtIndexPath:loopPath].accessoryType == UITableViewCellAccessoryCheckmark){

        [chosenSports addObject:[pickerTable cellForRowAtIndexPath:loopPath].textLabel.text];                          

    }

}

此代码会产生 sigabrt 错误。确切的错误是“与 UITableView 一起使用的索引路径无效。传递给表视图的索引路径必须恰好包含两个指定部分和行的索引。如果可能,请使用 UITableView.h 中 NSIndexPath 上的类别。” 提前致谢;

4

2 回答 2

4

错误是正确的。 NSIndexPaths由一行和一个节号组成,考虑到它们实际上对您的实现是多么盲目(考虑到它们依赖于数据源和委托),对于表视图尤其如此。你有一个简单的初始化错误,试试这个:

for(NSUInteger j = 0 ; j < [sports count] ; j++){

    NSIndexPath *loopPath = [NSIndexPath indexPathForRow:j inSection:0]; 

    if([pickerTable cellForRowAtIndexPath:loopPath].accessoryType == UITableViewCellAccessoryCheckmark){

        [chosenSports addObject:[pickerTable cellForRowAtIndexPath:loopPath].textLabel.text];                          

    }

}
于 2012-08-18T03:40:26.773 回答
2

除了@CodaFi 的回答,您应该知道cellForRowAtIndexPath返回nil当前不可见的行。

因此,您的循环仅添加当前可见单元格中的对象,这可能不是您想要的。

于 2012-08-18T07:29:35.880 回答