[英]When editing, `UITableView` does not call didSelectRowAtIndexPath ??
[英]didSelectRowAtIndexPath does not work when uitableview datasource is filtered
我有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];
}
所以,謝謝你
經過一番搜索,我發現我應該再設置一件事了
searchDisplayController.searchResultsDelegate = self;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.