我试图在不依赖 indexPaths 的情况下检查 tableView 中的一行。这类似于我之前问过的一个问题,但这似乎应该比它更容易。
我有一个静态值数组,它是我的 tableView 的数据源,称之为 fullArray。选择行时,它的值放在另一个数组中 - 允许呼叫它PartialArray。在我使用 indexPaths 执行此操作之前,我会使用以下方法迭代 partialArray:
for(NSIndexPath * elem in [[SharedAppData sharedStore] selectedItemRows]) {
if ([indexPath compare:elem] == NSOrderedSame) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
奇迹般有效。但是,现在我正在尝试使用部分数组中的值来执行此操作,但遇到了麻烦。
以下是我认为它应该在我的 sudo 代码中的 cellForRowAtIndexPath 方法中工作的方式:
对于 fullArray 中的每个字符串,如果它在 partialArray 中,则获取它的 indexPath 并检查它。
我开始拼凑的代码:
for(NSString *string in fullArray) {
if (partialArray containsObject:string) {
//Need help here. Get the index of the string from full array
fullArray indexOfObject:string];
//And check it.
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
看起来它不应该那么难,但我无法绕过它。