【问题标题】:Create search field in Tableview在 Tableview 中创建搜索字段
【发布时间】:2011-05-11 11:18:02
【问题描述】:

我正在创建一个带有表格视图的应用程序,其中包含大量数据。因此,我需要使用搜索字段。

有人知道如何在表格视图中创建搜索选项吗?

【问题讨论】:

  • 你也应该标记你的编程语言。对于我的回答,我只是假设您使用的是 Objective - C...
  • 在数组中搜索并在另一个数组中添加过滤的对象在表格视图中显示结果。在谷歌上搜索你会找到一个。
  • 是的朋友,我在 Iphone 中使用目标 C

标签: iphone objective-c ios uitableview uisearchbar


【解决方案1】:

使用 UISearchBar 属性,使用声明它

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,30)];

并将其作为子视图添加到您的 UIViewController 的视图中。

之后,在视图控制器中使用搜索栏委托方法:

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

查看this 教程,了解搜索栏及其代表!

编辑:此方法不是在 tableview 本身中使用搜索栏,而是在它之上。这意味着您必须将 tableView 作为 UIViewController 的子视图,并将 searchBar 作为同一 UIViewController 的子视图!

【讨论】:

猜你喜欢
  • 2017-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
相关资源
最近更新 更多