I m using UISearchDisplayController
in my one of screen of iphone application.my need is to see only a UISearchDisplayController
as user type in uisearchbar it will load the searchtableview and show data.now my problem is everything is going gud but when i try to select the row of search tabelview my -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
delegate not firing and thus the searchtableview never hides after it untill i click on cancel button of search-bar.and when i try to tap the row of searchtabelview my search bar hides and only serachtableview not hide and nothing can happen on did-select deleget method.
i have done folwing thing .so can anyone please tell me what my mistake is.
NOTEL:i dont have any other tableview in screen.just uisearchtableview of search display controller(is that causing a problem?)
self.searhController = [[UISearchDisplayController alloc]
initWithSearchBar:self.searchBar
contentsController:self];
self.searhController.delegate=self;
self.searhController.searchResultsDataSource = self;
self.searhController.searchResultsDelegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.searhController setDelegate:self];
[self.searhController setSearchResultsDelegate:self];
[self.searhController setSearchResultsDelegate:self];
#pragma mark TableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView== self.searhController.searchResultsTableView) {
if(self.searchResults.count<=0)
return 0;
else
return self.searchResults.count;
}
else{
return 0; }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
tableView.delegate=self;
tableView.dataSource=self;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(tableView==self.searhController.searchResultsTableView){
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
City *cityObj=[self.searchResults objectAtIndex:indexPath.row];
cell.textLabel.text = cityObj.name;
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView==self.searhController.searchResultsTableView) {
[self.searhController setActive:NO animated:YES];
[self.searchDisplayController setActive:NO animated:YES];
[self.searhController setActive:NO animated:NO];
}
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
if ([[searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length])
self.tvSearchView = self.searhController.searchResultsTableView;
else
self.tvSearchView = controller.searchResultsTableView;
if(searchString.length>=3){
[self getCityList:searchString];
return YES;
}
else{
return NO;
}
}