xcode 5在搜索时选择tableview
我有个问题。我需要在搜索时选择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
- (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;}看看我的演示项目——我刚刚用链接更新了答案。