可以这样做,自己写一个Controller把,逻辑都放在这里。
然后定义单独的UISearchDisplayController,设置resultDelegate和resultDataSource,代码如下:
MySearchDisplayViewController.h
@interface MySearchDisplayViewController : UIViewController
<UISearchDisplayDelegate, UITableViewDelegate, UITableViewDataSource>
ViewController.m
MySearchDisplayViewController *mySearchDisplayViewController = [[MySearchDisplayViewController alloc] init];
UISearchDisplayController *searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
searchDisplayController.delegate = mySearchDisplayViewController;
searchDisplayController.searchResultsDataSource = mySearchDisplayViewController;
searchDisplayController.searchResultsDelegate = mySearchDisplayViewController;