Use UISearchDisplayController as a superclass
I've put a lot of effort into creating a solid UITableViewController with custom cells. Now I want to create a separate UITabbarItem that uses that UITableViewController within a UISearchDisplayController.
Adhering to OO design principles, I imagine that when defining the UISearchDisplayController I'd subclass the original UITableViewController.
e.g.
@interface SearchViewController : CustomTableViewController
{
NSArray *listContent; // The master content.
NSMutableArray *filteredListContent; // The content filtered as a result of a search.
// The saved state of the search UI if a memory warning removed the view.
NSString *savedSearchTerm;
NSInteger savedScopeButtonIndex;
BOOL searchWasActive;
}
However this approa开发者_运维技巧ch doesn't work at all - the cells are not updated at all in SearchViewController, and the UITableView delegate methods do not seem to have an effect (e.g. rows are not resized).
So I have several questions:
Is this the correct way to go about this, if so, how do I update the listContent and the filteredListContent from the superview.
Would it be better to just add a UISearchBar to the original search view and hide it as necessary?
I don't think you can subclass UISearchDisplayController and have it work correctly. It does a lot of stuff in methods which aren't public, so you wouldn't be able to override them with the correct behavior.
You can, however, use the built in UISearchDisplayController with your custom table cells in the search results, as is. You need to encapsulate the creation and configuring of your custom cells such that it works in any table view just by overriding -...cellForRowAtIndexPath (this is the standard method of displaying custom data in a tableview). Make sure that controller is the UISearchDisplayDelegate and it'll use that method to create the rows in your search list.
To set the custom height, implement
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)searchTableView
to set the rowHeight on the searchTableView.
精彩评论