gpt4 book ai didi

ios - 使用 UISearchDisplayController 作为父类(super class)

转载 作者:行者123 更新时间:2023-11-28 17:45:00 25 4
gpt4 key购买 nike

我付出了很多努力来创建带有自定义单元格的可靠 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 委托(delegate)方法似乎没有效果(例如,行没有调整大小)。

所以我有几个问题:

  1. 这是解决此问题的正确方法吗?如果是这样,我该如何从 super View 更新 listContent 和 filteredListContent。

  2. 只在原始搜索 View 中添加一个 UISearchBar 并根据需要隐藏它会更好吗?

最佳答案

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

但是,您可以将内置的 UISearchDisplayController 与搜索结果中的自定义表格单元格一起使用,照原样。您需要封装自定义单元格的创建和配置,以便它可以在任何 TableView 中工作,只需覆盖 -...cellForRowAtIndexPath(这是在 TableView 中显示自定义数据的标准方法)。确保 Controller 是 UISearchDisplayDelegate,它将使用该方法在搜索列表中创建行。

要设置自定义高度,实现

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

设置 searchTableView 的行高。

关于ios - 使用 UISearchDisplayController 作为父类(super class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6459673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com