sin*_*h99 5 iphone objective-c uitableview uisearchbar ios
我正在创建一个带有表视图的应用程序,其中包含大量数据.因此,我需要使用搜索字段.
有谁知道如何在tableview中创建搜索选项?
使用UISearchBar属性,使用声明它
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,30)];
Run Code Online (Sandbox Code Playgroud)
并将其作为子视图添加到UIViewController的视图中.
之后,在视图控制器中使用searchbar委托方法:
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
Run Code Online (Sandbox Code Playgroud)
查看本教程,了解搜索栏及其代理人!
编辑:此方法不是在tableview本身使用搜索栏,而是在其上方.这意味着您必须将tableView作为UIViewController的子视图,并将searchBar作为同一UIViewController的子视图!