0

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;
    }

}
BhavikKama
  • 8,566
  • 12
  • 94
  • 164
  • set break point before if loop in didselectRow and try once whether its firing? – Yohan Aug 07 '14 at 11:50
  • i have tried that its not firing and cellforrowatindex is firing that time.when i scroll tableview but not didselect – BhavikKama Aug 07 '14 at 11:50
  • sure you could have been set delegate properly. Where you set breakpoint before if loop right? – Yohan Aug 07 '14 at 11:52
  • you set delegate using coding or using IBOutlet? and do you have added any gesture to the view – Yohan Aug 07 '14 at 11:55
  • oops i have set some gesture on uiview for hiding keyboard.. its solved..thanx – BhavikKama Aug 07 '14 at 11:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58875/discussion-between-yohan-and-bhavik-kama). – Yohan Aug 07 '14 at 11:57

1 Answers1

1

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

Yohan
  • 1,108
  • 9
  • 21