gpt4 book ai didi

objective-c - 遍历 TableView 单元格

转载 作者:行者123 更新时间:2023-11-28 18:24:59 25 4
gpt4 key购买 nike

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 一起使用的索引路径无效。传递给 TableView 的索引路径必须恰好包含两个指定部分和行的索引。如果可能,请在 UITableView.h 中使用 NSIndexPath 上的类别。”提前致谢;

最佳答案

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

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];

}

}

关于objective-c - 遍历 TableView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12015613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com