【问题标题】:Is there a way to pre-populate UISearchDisplayController with results before the user starts typing in the SearchBar?有没有办法在用户开始在 SearchBar 中输入之前用结果预填充 UISearchDisplayController?
【发布时间】:2012-07-09 16:25:54
【问题描述】:

我想在搜索栏激活后立即显示过去的搜索。但即使数据源有这些值,搜索显示控制器在用户开始输入之前不会调用表格视图方法。有没有办法在 UISearchDisplayController 上强制执行此操作?

【问题讨论】:

    标签: iphone objective-c uisearchbar uisearchdisplaycontroller


    【解决方案1】:

    只要您的委托设置正确,您就可以返回任何您想要的数据集。

     self.searchResults = @[@"some stuff", @"some more stuff", @"and so on..."];
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
       if (tableView == [[self searchDisplayController] searchResultsTableView]) {
         return [self.searchResults count];
       }
       else {
         return [self.data count];
       }
    }
    

    【讨论】:

    • 在您开始在搜索栏中输入您的内容之前,表格视图不会显示。
    猜你喜欢
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2022-06-24
    • 1970-01-01
    相关资源
    最近更新 更多