Krunal
Krunal

Reputation: 6490

searchBarTextDidBeginEditing delegate method called again on back button click

I am developing iPhone app in which i got stuck at one point.

I have one viewController with navigation bar hidden and search bar is in the centre of the page.

when user clicks on searchBar searchBarTextDidBeginEditing method gets fired.

after this on text change of searchBar textDidChange method i am loading live data in tableview and on click of tableview i am navigating to other page with navigation bar non hidden.

Now when i press back button again i comes to search page here searchBarTextDidBeginEditing method again gets fired.

Why this method gets called again on back press ?

Please help and thanks in advance.

Upvotes: 1

Views: 1193

Answers (2)

tgyhlsb
tgyhlsb

Reputation: 1915

I think the UITextField keeps the focus on itself when you navigate.

Try [textField resignFirstResponder] when you click on your tableView to navigate.

Upvotes: 1

Vishal Sharma
Vishal Sharma

Reputation: 1733

Your SearcBarTextDidBeginEditing called due to your search display controller still in Active mode,

In your TableView Delegate Method,

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [self.view endEditing:YES];
    [self.searchDisplayController.searchBar resignFirstResponder];


   // Set Navigation
}

And In Same Class , In View Will Appear SET,

-(void)viewWillAppear:(BOOL)animated{

    self.searchDisplayController.Active = NO;

}

Hope this will help you!

Upvotes: 5

Related Questions