Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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
Iphone 筛选uitableview数据源时,didSelectRowAtIndexPath不工作_Iphone_Uitableview - Fatal编程技术网

Iphone 筛选uitableview数据源时,didSelectRowAtIndexPath不工作

Iphone 筛选uitableview数据源时,didSelectRowAtIndexPath不工作,iphone,uitableview,Iphone,Uitableview,我有uitableview和带有searchDisplayController的搜索栏,我用数据库中的数据填充tableview数据源,我使用搜索栏进行搜索,当uitableview数据源未被过滤时,didSelectRowAtIndexPath工作正常,它进入detailviewcontroller,但是当我使用搜索和筛选数据源时,如果我选择一个单元格,didSelectRowAtIndexPath方法不会触发 - (void)tableView:(UITableView *)tableVie

我有uitableview和带有searchDisplayController的搜索栏,我用数据库中的数据填充tableview数据源,我使用搜索栏进行搜索,当uitableview数据源未被过滤时,didSelectRowAtIndexPath工作正常,它进入detailviewcontroller,但是当我使用搜索和筛选数据源时,如果我选择一个单元格,didSelectRowAtIndexPath方法不会触发

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    KardexViewController* kardexViewController = [[KardexViewController alloc] initWithStyle:UITableViewStylePlain];

    [self.navigationController pushViewController:kardexViewController animated:YES];
}
这就是我添加uisearchbar的方式

- (void)viewDidLoad
{
    [super viewDidLoad];

    dataSource = [[NSMutableArray alloc] init];

    self.navigationItem.title = Title;

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;

    self.tableView.tableHeaderView = searchBar; 
}
以及如何过滤数据源

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    NSMutableArray* result = [[NSMutableArray alloc] init];

    for (int i = 0; i < [self.allData count]; i++) {
        NSRange range = [[[self.allData objectAtIndex:i] valueForKey:@"Code"] rangeOfString:searchString];

        if(range.length > 0)
            [result addObject:[self.allData objectAtIndex:i]];

        range = [[[self.allData objectAtIndex:i] valueForKey:@"Name"] rangeOfString:searchString];

        if(range.length > 0)
            [result addObject:[self.allData objectAtIndex:i]];
    }

    self.dataSource  = [result copy];
    [result release];
    [self.searchDisplayController.searchResultsTableView reloadData];

    return YES;
}

-(void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
    self.dataSource  = [self.allData copy];
}
-(BOOL)searchDisplayController:(UISearchDisplayController*)控制器应重新加载TableForSearchString:(NSString*)searchString
{
NSMUTABLEARRY*结果=[[NSMUTABLEARRY alloc]init];
对于(int i=0;i<[self.allData count];i++){
NSRange range=[[self.allData objectAtIndex:i]valueForKey:@“Code”]rangeOfString:searchString];
如果(range.length>0)
[结果添加对象:[self.allData objectAtIndex:i]];
range=[[self.allData objectAtIndex:i]valueForKey:@“Name”]rangeOfsString:searchString];
如果(range.length>0)
[结果添加对象:[self.allData objectAtIndex:i]];
}
self.dataSource=[结果副本];
[结果发布];
[self.searchDisplayController.searchResultsTableView重新加载数据];
返回YES;
}
-(void)SearchDisplayControllerDendSearch:(UISearchDisplayController*)控制器
{
self.dataSource=[self.allData copy];
}

所以谢谢你的帮助,经过一番搜索,我发现我应该再做一件事

searchDisplayController.searchResultsDelegate = self;

请提供您如何使用搜索和文件管理器的代码。其中的表将出现一些问题,因此它无法正常工作,或者完全感谢您回来回答您自己的问题。一段时间以来,我一直在琢磨这个问题,想着searchDisplayController.delegate=self;够了,还不够,我需要添加你的代码,现在一切都好了。@Ali,iSearchDisplayController在iOS 8中不受欢迎。现在的解决方案是什么?你能和我分享一下吗?@Narasimhanalamsetty对不起,我很久没有使用本机移动应用了。