我有一个带有 2 个数组的视图控制器,一个用于正常结果;另一个用于基于文本输入的过滤/搜索结果。
一次只能有一个单元格有 UITableViewCellAccessoryCheckmark。
我的问题可以这样描述;
IE:
- 视图控制器被提供了一个场地对象;并用 UITableViewCellAccessoryCheckmark 标记。这是预期的,也是正确的。
- 用户输入搜索查询,使用搜索结果数组;但是 UITableViewCellAccessoryCheckmark 不再位于先前在步骤 1 中检查的 Venue 上。
我不确定为什么它不检查单元格。
视觉示例;
原始视图。Cobo Arena
是预选的场地
-
打字时;复选标记不在正确的位置
-
更多输入:复选标记现已消失
-
代码如下
- (void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
FCVenue *venue;
if (self.isSearching)
{
venue = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
venue = [self.venues objectAtIndex:indexPath.row];
}
if ([indexPath isEqual:self.selectedIndexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", venue.name];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", venue.location];
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView cellForRowAtIndexPath:self.selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
self.selectedIndexPath = indexPath;
[self.tableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
FCVenue *venue;
if (self.searching)
{
venue = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
venue = [self.venues objectAtIndex:indexPath.row];
}
self.selectedVenue = venue;
// This method fires a completion block and dismisses the view controller
if (self.completionBlock)
{
self.completionBlock( self, self.selectedVenue );
}
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}