iOS UISearchDisplayController学习笔记

时间:2014-10-10 11:18:35   收藏:0   阅读:282

UISearchDisplayController和UISearchBar一起使用用来管理UISearchBar和搜索结果的展示。UISearchDisplayController提供了显示搜索结果的tableview来覆盖原控制器的视图;

使用UISearchDisplayController需要:

通常是在在uitableview中初始化UISearchDisplayController来展示一个列表;

searchController = [[UISearchDisplayController alloc]
                         initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;

在tabelview代理方法中需要判断是哪一个table(UITableViewController中有self.tableView  UISearchDisplayController中有.searchResultsTableView)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 
    if (tableView == self.tableView) {
        return ...;
    }
    // If necessary (if self is the data source for other table views),
    // check whether tableView is searchController.searchResultsTableView.
    return ...;
}
一个UIViewController和一个UISearchBar只有一个UISearchDisplayController;


你能够在ios7 之后,在navigationbar中使用SearchDisplayController,通过配置UISearchDisplayController中得displaysSearchBarInNavigationBar和 navigationItem属性;


相关的属性和方法

@property(nonatomic, getter=isActive) BOOL active

展现(是否隐藏)状态,默认值是NO,直接设置没有动画,用setActive:animated: 设置会有动画

@property(nonatomic, assign) id<UISearchDisplayDelegate> delegate

代理

@property(nonatomic, assign) BOOL displaysSearchBarInNavigationBar

指定navigationbar中包含一个searchBar

@property(nonatomic, readonly) UINavigationItem *navigationItem

只读属性 代表在navigation controller的navigationbar中的searchdisplaycontroller;

@property(nonatomic, readonly) UISearchBar *searchBar

UISearchDisplayController中的UISearchBar;

@property(nonatomic, readonly) UIViewController *searchContentsController

这个属性管理着搜索出的内容

@property(nonatomic, assign) id<UITableViewDataSource> searchResultsDataSource

展示搜索结果的数据来源

@property(nonatomic, assign) id<UITableViewDelegate> searchResultsDelegate

搜索结果展示的table的代理

@property(nonatomic, readonly) UITableView *searchResultsTableView

搜索结果展示的table

@property(nonatomic, copy) NSString *searchResultsTitle

搜索结果视图的标题

- (id)initWithSearchBar:(UISearchBar *)searchBar contentsController:(UIViewController *)viewController

初始化控制器 指定关联的search 和view controller

- (void)setActive:(BOOL)visible animated:(BOOL)animated

展现或者隐藏搜索视图

内容来自苹果文档


原文:http://blog.csdn.net/u010123208/article/details/39956477

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!