Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot dismiss the Search view

I have a parent class with tableview and searchbar over it which is a subclass of tableview controller. Delegates for the searchBar and searchdisplaycontroller are set in a seperate class inherited from UISearchdisplaycontroller. The datasource and delegates for tableview and searchbar are handled in this class seperately. The classes are under ARC.

Hence, When a user taps on search, the control transfers from FilesListController (parent)class to this class. Now, When a user taps on cancel button, the searchbar delegate set in this class i.e.

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar  

is CALLED but DOESN'T serve the purpose of dismissing the full screen searchtableview and return to the parentviewcontroller. However, if I don't write this delegate in the search class, it works properly. I have set the searchbar delegates in xib and on calling:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar

like this:

self.searchResultsTableView.delegate = self;
self.searchResultsTableView.dataSource = self;
[parentFileViewController.searchDisplayController setDelegate:self];

Where am I going wrong? Thanks in advance.

like image 245
tech savvy Avatar asked Aug 27 '12 08:08

tech savvy


2 Answers

If you want to dismiss a UISearchBar with a SearchBarController, just use this Code:

[self.searchDisplayController setActive:NO animated:YES];
like image 152
jussi Avatar answered Sep 17 '22 23:09

jussi


you should implement resign the responder in the delegate function i.e

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
      [searchBar resignFirstResponder];
 }
like image 41
cekisakurek Avatar answered Sep 17 '22 23:09

cekisakurek