0
我有一個視圖控制器2個數組,一個用於正常結果;另一個是基於文本輸入的過濾/搜索結果。當搜索如何使UITableViewCellAccessoryCheckmark正確的單元格?
一次只有一個單元格可以具有UITableViewCellAccessoryCheckmark。
我的問題可以這樣描述;
IE:
- 視圖控制器被送入一個地點對象;並用 UITableViewCellAccessoryCheckmark標記。這是預期的,並且是正確的。
- 用戶類型在搜索查詢中,使用搜索結果數組; 但是UITableViewCellAccessoryCheckmark是先前在步驟1中
檢查 地點不再是我不知道爲什麼它不檢查電池。
Visual examples;
原始視圖。 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:^{
}];
}