gpt4 book ai didi

ios - 如何在 UITableView 和搜索栏中使用 "sublists"?

转载 作者:行者123 更新时间:2023-11-29 10:58:55 25 4
gpt4 key购买 nike

我想要做的是:它基本上是一个表格 View ,显示一些具有许多值的单元格。

enter image description here

选择一个值细胞时,它将从所选值的值中打开带有子值的新单元。

enter image description here

它还会让用户能够在这些单元格之间进行搜索。

enter image description here

我已经使用了很多 UITableViews,所以我在选择、显示数据、处理事件等方面没有问题。我从未使用过带有搜索栏的 TableView ,但从我在许多教程中标出的内容来看,它看起来并不那么复杂。所以只有两点我需要你的帮助。

  • 点击值单元格时显示这些新单元格的最佳方式是什么(当然,在重新点击值单元格时再次隐藏它们)。
  • 最棘手的一点似乎在这里,我如何使用搜索栏只查找值单元格中的数据而不是子值单元格中的数据?例如,如果用户已经点击并打开了值 2 和 5 的子值,如果他在搜索栏中插入“2”,则值“5”的单元格及其所有子值单元格将被隐藏,但“2”一个将继续显示其子值。

感谢您的帮助。

最佳答案

What is the best way to display these new cells when value cells are tapped (and of course hide them again in case of re-tapped value cell).

最简单的方法是在展开单元格时向数据数组添加更多行,并在折叠时删除它们。自定义“子列表单元格”的外观并跟踪当前展开的单元格。您还可以考虑使用 https://github.com/OliverLetterer/UIExpandableTableView (我没有使用过它,所以不能对它发表评论)。

The most tricky point seems to be here, how can I use the search bar to look ONLY for data in value cells and not in subvalue ones? For example, if a user has already tapped and opened subvalues from values 2 and 5, if he inserts "2" in the search bar, the cell with value "5" and all its subvalue cells will be hidden, but the "2" one will keep being displayed with its subvalues.

这是比较容易的部分,我想说。您负责搜索 TableView 数据并向搜索显示 Controller 提供过滤列表。这是通过以下两种方法完成的:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText: searchString
scope: [self.searchDisplayController.searchBar scopeButtonTitles][[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText: [self.searchDisplayController.searchBar text]
scope: [self.searchDisplayController.searchBar scopeButtonTitles][searchOption]];
return YES;
}

filterContentForSearchText:scope: 方法中,只搜索“ super 列表单元格”,而不搜索“子列表单元格”。您可以自定义搜索显示表格的单元格,使其看起来像 super 列表/子列表:UITableView Controller with prototype custom cell and search display controller tableview

希望这对您有所帮助!

关于ios - 如何在 UITableView 和搜索栏中使用 "sublists"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16934767/

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