Reputation: 8790
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;
}
}
Upvotes: 0
Views: 830
Reputation: 1108
As per you You set some tapGesture to the view so don add gesture to the view at viewDidLoad()
. Add Gesture to the view when you start typing in the textfield and when you didFinish
typing remove the gesture from the view. So it won affect tableview from didslect()
problem
Upvotes: 1