Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xcode 5在搜索时选择tableview_Xcode_Search_Select_Tableview - Fatal编程技术网

xcode 5在搜索时选择tableview

xcode 5在搜索时选择tableview,xcode,search,select,tableview,Xcode,Search,Select,Tableview,我有个问题。我需要在搜索时选择tableview 在正常模式下,这是正常的,但当我搜索它什么也不做。代码很简单 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; if(cell.accessory

我有个问题。我需要在搜索时选择tableview

在正常模式下,这是正常的,但当我搜索它什么也不做。代码很简单

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{  
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    if(cell.accessoryType == 0){
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = cell.accessoryType = UITableViewCellAccessoryNone;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
对于选择模式,我使用:

 -(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text {
    if(text.length == 0)
    {
       isFiltered = FALSE;
    } else {
       isFiltered = true;
    }
 }

搜索显示控制器在显示搜索结果时覆盖其自己的表视图。因此,在对表视图点击做出反应之前,需要检查当前显示的表视图

以下是您可以确定的方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if (tableView == self.tableView) {
    // it's your "real" table view
} else {
    // search results table view
}
}

GitHub上有一个演示项目,在工作项目的上下文中显示了这一点:

不起作用(((使用简单的测试代码检查-(void)tableView:(UITableView*)tableView DidSelectRowatineXpath:(NSIndexPath*)indexPath{UITableViewCell*cell=[self.tableView CellForRowatineXpath:indexPath];如果(tableView==self.tableView){cell.accessoryType=UITableViewCellAccessoryCheckmark;}其他{cell.accessoryType=UITableViewCellAccessoryCheckmark;}看看我的演示项目——我刚刚用链接更新了答案。