I have a tableview
for showing a list of devices in my application. When viewWillAppear is called, I add the self.searchDisplayController.searchBar as a subview to a headerView
. I then assign self.tableView.tableHeaderView = headerView
. It looks like this:
I scroll the tableview down so that headerview goes out of view and then go to some other view controller by tapping on a cell. When I come back to this tableView, scroll up to the headerView, the searchBar becomes invisible, however on tapping the invisible area the searchDisplayController gets activated and the cancel button doesn't work. This happens for iOS 7 only. Why is this happening?
Note: It happens only if the headerView is out of the view when I come back to the tableViewController.
I've just had the same issue. When I go to debug into the delegate method of UISearchDisplayController at the end search state, the searchBar becomes a subview of an UIView, not the UITableView. Please see below code:
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { //My Solution: remove the searchBar away from current super view, //then add it as subview again to the tableView UISearchBar *searchBar = controller.searchBar; UIView *superView = searchBar.superview; if (![superView isKindOfClass:[UITableView class]]) { NSLog(@"Error here"); [searchBar removeFromSuperview]; [self.tableView addSubview:searchBar]; } NSLog(@"%@", NSStringFromClass([superView class])); }
My solution is remove the searchBar away from current super view, then add it as subview again to the tableView. I've already tested successfully. Hope that help!
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With