Cannot dismiss the Search view
ios, objective-c, uisearchbar, uisearchdisplaycontroller, uitableview
Solution
If you want to dismiss a UISearchBar with a SearchBarController, just use this Code:
[self.searchDisplayController setActive:NO animated:YES];
Problem
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.