开发者

table view is no longer a searchResultsTableView after returning from a detail view

I'm using a UISearchDisplayController based on this tutorial: http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html

I've a table view in navigation controller with that search controller. And as usual, you can search, click on the search result and go to detail view.

I'm using such code like the following to detect whether the current table view is searchResultsTableView.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if(tableView == self.searchDisplayController.searchResultsTableView)
        return 1;
    else
        return [self.arrCharacters count];
}

My problem is when the user come back from detail view to the search result table view, that tableView becomes normal table view and not a searchResultsTableView anymore. But the table is still filtered and only show the search results. Just the tableView is no longer recognized as a searchResultsTableView. So all my index calculations go wrong and app crashes.

Any help is greatly appreciated.

Many 开发者_如何学运维thanks,


One alternative way to solve this situation is set a flag whether your table is searchResultTableView or just normal tableView. For instance, when user did search in any chance, set your flag as true, and keep this value unless user click on cancel or any other way to finish search. Since you are using searchDisplayController, delegate method

-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller

will be called at the end of search, so you can change flag value to indicate normal table. Based on this flag value, you can put if statement in tableView delegate methods to set up table in a way you want to. However, when I attempt to check same situation as your case (search and click one of table cell and go back to previous table) in my app, tableView still hold as searchResultTableView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜