gpt4 book ai didi

ios - 不能将 UISearchController 与 UICollectionView 一起使用吗?

转载 作者:技术小花猫 更新时间:2023-10-29 11:00:11 26 4
gpt4 key购买 nike

在 WWDC 2014 演讲“深入了解 Presentation Controllers”中,演示者展示了如何在 UITableView 中设置 UISearchController。他们通过设置 searchController 的 searchBar 的框架,然后将其设置为 tableView 的 tableHeaderView 来实现。不幸的是,没有与 UICollectionView 对应的 tableHeaderView。使用 UISearchDisplayController,这会很简单:创建一个 UISearchBar 并将其添加到自定义 UICollectionView 部分标题,然后使用搜索栏初始化 UISearchDisplayController。问题是,您不能用 UISearchBar 初始化 UISearchController,甚至不能设置 searchBar,因为它是只读属性。我想我真正的问题是,我有什么选择?有没有不用 UISearchDisplayController 或 UISearchController 实现搜索的“好”方法?

最佳答案

With UISearchDisplayController, this would be simple: create a UISearchBar and add it to a custom UICollectionView section header, then initialize the UISearchDisplayController with the search bar

UISearchController 中的搜索栏是为您创建的。在数据源方法中询问补充 View 时

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

添加 searchController.searchBar 作为辅助 View 的 subview 。别忘了打电话

[searchController.searchBar sizeToFit]

为了给搜索栏适当的大小。

关于ios - 不能将 UISearchController 与 UICollectionView 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24962282/

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