gpt4 book ai didi

带有自定义单元格的 Ios/swift/UISearchController 或 SearchDisplayController

转载 作者:搜寻专家 更新时间:2023-11-01 07:21:49 25 4
gpt4 key购买 nike

我目前有一个应用程序,其导航栏顶部有一个搜索图标/按钮。

我不确定 Storyboard是否可行,但我想显示一个带有自定义表格 View 和关闭按钮的搜索 Controller ,很像维基百科应用程序

看下面的例子

http://i.imgur.com/ggsTj6W.png

http://i.imgur.com/BVDLU2O.jpg

所以工作流程是:- 按搜索图标,- 表格 View 带有以关闭按钮为中心的搜索- 搜索结果作为来自可重用源的自定义单元格出现在表格 View 中

当我在维基百科应用程序上使用此搜索时,它感觉非常适合 ios,所以我认为有办法做到这一点?

谢谢

最佳答案

  1. 创建一个 UITableViewController 对象并使其符合协议(protocol) UISearchResultsUpdating

  2. 将搜索 Controller 添加到类中

    let searchController = UISearchController(searchResultsController: nil)
  3. 在viewdidload方法中添加如下代码

    self.definesPresentationContext = true
    searchController.searchResultsUpdater = self
    searchController.hidesNavigationBarDuringPresentation = true
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar
  4. 实现以下方法以符合UISearchResultsUpdating协议(protocol)

    func updateSearchResultsForSearchController(searchController: UISearchController)
  5. 在主页面上(您想要显示搜索按钮的地方),为上面的 tableViewController 创建一个 segue,并将其设置为在点击按钮时以模态方式呈现。

关于带有自定义单元格的 Ios/swift/UISearchController 或 SearchDisplayController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38515357/

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