Noa*_*oam 10 iphone uitableview uisearchbar uisearchdisplaycontroller
我有一个searchDisplayController搜索a UITableView.
输入搜索字词后,我可以看到UITableView包含搜索结果的其他字词.但是,我希望这UITableView是GROUPED,而不是PLAIN(默认情况下是这样).
我该怎么做呢?
小智 15
这对我有用(iOS 5.0):
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[self.searchController setValue:[NSNumber numberWithInt:UITableViewStyleGrouped]
forKey:@"_searchResultsTableViewStyle"];
Run Code Online (Sandbox Code Playgroud)
chr*_*tfr 14
如果 - 像我一样 - 你认为普通的TableView太难看了,你也可以放弃使用SearchDisplayController.
我只是:
[self.resultTableView reloadData];在这里,您可以找到我在代表中使用的所有方法
@interface MyViewController : UIViewController <UIApplicationDelegate, UISearchBarDelegate> {
IBOutlet UISearchBar *searchBar;
IBOutlet UITableView *resultTableView;
}
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;
@property (nonatomic, retain) IBOutlet UITableView *resultTableView;
//For your searchBar the 2 most important methods are
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBarClicked;
- (BOOL)searchBarTextDidEndEditing;
//For your TableView the most important methods are in my case:
//number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
//HEADERS
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
//different numbers of row by section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
//the cells themselves
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@end
Run Code Online (Sandbox Code Playgroud)
毕竟,最简单的解决方案往往是最好的......
| 归档时间: |
|
| 查看次数: |
10517 次 |
| 最近记录: |