我有一个表格视图,列出国家和我可以选择多个原始数据。我有选择和取消选择原始选项的选项。当我添加一个搜索栏时出现问题,我无法取消选择结果列表的原始数据,因为方法" didDeselectRowAtIndexPath"我按下结果项时从不调用。
我搜索了这个问题,但没有,
提前致谢,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
//[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:indexPath.row];
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = NO;
tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
NSDictionary *country = [self.searchResult objectAtIndex:indexPath.row];
[self.selectedItems addObject: country];
}
else
{
//[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:indexPath.row];
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = NO;
tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
NSDictionary *country = [self.countriesArray objectAtIndex:indexPath.row];
[self.selectedItems addObject: country];
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
//[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = YES;
tableViewCell.accessoryType = UITableViewCellAccessoryNone;
NSDictionary *country = [self.searchResult objectAtIndex:indexPath.row];
[self.selectedItems removeObject:country];
}else
{
//[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = YES;
tableViewCell.accessoryType = UITableViewCellAccessoryNone;
NSDictionary *country = [self.countriesArray objectAtIndex:indexPath.row];
[self.selectedItems removeObject:country];
}
}