【问题标题】:Search bar in top of ViewContoller with UITableView and reload dataViewContoller 顶部的搜索栏与 UITableView 并重新加载数据
【发布时间】:2014-04-14 02:53:37
【问题描述】:

我有 ViewController 和 UITableViewController 在里面。在我的 VC 顶部,我得到了搜索栏。我需要将搜索栏与我的 tableView 连接起来。

  @interface MessageViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>

//.m

 self.searchDisplayController.searchBar.delegate = self;

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 270, kRowHeight)];
self.searchBar.delegate = self;
self.searchBar.backgroundColor = [UIColor colorWithWhite:0.9 alpha:0.7];
self.searchBar.barStyle = UISearchBarStyleDefault;
[self.view addSubview:self.searchBar];


#pragma mark - UISearchDisplayController Delegate Methods

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self doSearch];

return YES;
}

为什么我没有更新tableView

【问题讨论】:

    标签: ios uitableview tableview uisearchbar searchbar


    【解决方案1】:

    执行搜索后尝试调用[self.tableView reloadData];,在doSearch 方法的底部重新加载tableView 的内容。

    【讨论】:

    • 我在 kReloadMessageViewControllerScreen 中做
    • 我需要告诉 searchDisplayController DataSourse 在哪里进行搜索吗?
    • 如果他们是相关的,是的。
    • 我真的很高兴你做到了!感谢所有 cmets。
    猜你喜欢
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    相关资源
    最近更新 更多