UISearchDisplayController not working when created in code??
Posted
by Nick Bedford
on Stack Overflow
See other posts from Stack Overflow
or by Nick Bedford
Published on 2010-03-07T05:14:52Z
Indexed on
2010/05/24
7:31 UTC
Read the original article
Hit count: 481
I'm working on a tab bar application and one of the tabs has a UISearchDisplayController hooked up to a UISearchBar. It's all connected up in the NIB and is working. When I tap the search bar, the Scope and Cancel buttons fly in etc, and the search delegate updates the results table correctly.
However, I'm trying to implement the same code in the viewDidLoad
message instead of the NIB, however when I delete the search display controller from the NIB and uncomment my code to create the same controller in the function, it doesn't work. It's as if there's some fundamental connection not being made so that all my search delegate functionality isn't being called.
Here's my working NIB version of the Search Display Controller. It's hooked up to the search bar, the UINavigationController
subclass (MASearchController
) and the root view of that is hooked up as the searchContentsController
.
Now this is what you would expect to do in code to create the same, right? What I'm doing is leaving the UISearchBar in the NIB to eliminate one piece of the puzzle at a time in code.
// [MASearchController viewDidLoad]
UISearchDisplayController *searchController = [[[UISearchDisplayController alloc]
initWithSearchBar:searchBar
contentsController:[[self viewControllers] objectAtIndex:0]] autorelease];
[searchController setDelegate:self];
[searchController setSearchResultsDelegate:self];
[searchController setSearchResultsDataSource:self];
I've checked all objects at run time and they all check out. Essentially I've deleted the search display controller from the NIB and then put in the code to create it in the viewDidLoad
message.
Why would this not work? The search keyboard comes up but none of my search and button animation functionality work???
© Stack Overflow or respective owner