在做搜索框的時候用到UISearhcDisplay,但是我發現這樣的話,所有的處理Display的那個TableView的邏輯就都要和搜索框放在同一個類里。而我帶搜索框的這個類結構是,上邊一個搜索框下邊一個TableView。這樣的話,我在TableView的delegate方法就要通過區分tableView的對象,然后做不同的處理。統一各類,同一個方法太長了。
1 回答

牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
可以這樣做,自己寫一個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;
- 1 回答
- 0 關注
- 155 瀏覽
添加回答
舉報
0/150
提交
取消