【问题标题】:Use UISearchDisplayController as a superclass使用 UISearchDisplayController 作为超类
【发布时间】:2011-06-23 19:38:46
【问题描述】:

我付出了很多努力来创建一个带有自定义单元格的可靠 UITableViewController。现在我想创建一个单独的 UITabbarItem,它在 UISearchDisplayController 中使用该 UITableViewController。

秉承 OO 设计原则,我想在定义 UISearchDisplayController 时,我会将原来的 UITableViewController 子类化。

例如

@interface SearchViewController : CustomTableViewController
{
    NSArray         *listContent;           // The master content.
    NSMutableArray  *filteredListContent;   // The content filtered as a result of a search.

    // The saved state of the search UI if a memory warning removed the view.
    NSString        *savedSearchTerm;
    NSInteger       savedScopeButtonIndex;
    BOOL            searchWasActive;
}

但是这种方法根本不起作用 - SearchViewController 中的单元格根本没有更新,并且 UITableView 委托方法似乎没有效果(例如,行没有调整大小)。

所以我有几个问题:

  1. 这是解决此问题的正确方法吗?如果是,我如何从超级视图更新 listContent 和过滤后的ListContent。

  2. 将 UISearchBar 添加到原始搜索视图并在必要时将其隐藏会更好吗?

【问题讨论】:

    标签: ios uitableview uisearchdisplaycontroller


    【解决方案1】:

    我不认为你可以继承 UISearchDisplayController 并让它正常工作。它在不公开的方法中做了很多事情,所以你不能用正确的行为覆盖它们。

    但是,您可以在搜索结果中将内置的 UISearchDisplayController 与您的自定义表格单元格一起使用。您需要封装自定义单元格的创建和配置,使其仅通过覆盖 -...cellForRowAtIndexPath 即可在任何表格视图中工作(这是在表格视图中显示自定义数据的标准方法)。确保控制器是 UISearchDisplayDelegate,它将使用该方法在搜索列表中创建行。

    要设置自定义高度,请实现

    - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)searchTableView
    

    在 searchTableView 上设置 rowHeight。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 2013-03-30
      相关资源
      最近更新 更多