In my project i need an UISearchBar
to scroll on an UITableView
. So i just put it on an UITableViewCell
like this:
searchBar = [[SearchBar alloc] initWithFrame:cell.bounds];
searchBar.delegate = self;
searchBar.placeholder = NSLocalizedString(@"Search friends", "");
searchBar.layer.borderWidth = 1.f;
searchBar.layer.borderColor = [UIColor whiteColor].CGColor;
sdc = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:nil];
sdc.delegate = self;
[cell addSubview:searchBar];
and it works fine on iOS 6. But on iOS 7 it switches to another superview (and literally disappears from the screen) when just getting in focus. At first i thought it's something wrong with my project which causes such a behaviour but then i created a simple test project and i verified this - indeed, it's a rule, on iOS 7.1 UISearchBar
added to UITableViewCell
moves to another superview and gets lost from the screen right after becoming first responder.
I have overridden willMoveToSuperview:
method on the search bar and i see that it moves from UITableViewCellScrollView
to a view which class is UIView
and whose superview's class is UISearchDisplayControllerContainerView
.
After few hours of search and experiments i'm not able to figure out what causes this behaviour and how to escape it. All i know for sure is that it happens right between calls to these two UISearchDisplayDelegate
methods: searchDisplayControllerWillBeginSearch:
and searchDisplayControllerDidBeginSearch:
.
Did anyone ever encountered this? Any ideas how to resolve it?