gpt4 book ai didi

ios - UISearchController 搜索栏不隐藏导航栏

转载 作者:行者123 更新时间:2023-11-29 01:44:26 29 4
gpt4 key购买 nike

我有一个 UITableViewController 作为我的 UINavigationController 的根。激活搜索栏不会隐藏导航栏。我尝试了很多不同的配置,但似乎都不起作用。

class TableViewController < UITableViewController
def viewDidLoad
search_controller = UISearchController.alloc.initWithSearchResultsController(nil)
search_controller.searchResultsUpdater = self
search_controller.searchBar.delegate = self
search_controller.searchBar.sizeToFit
self.definesPresentationContext = true

self.tableView.tableHeaderView = search_controller.searchBar
end
end

这是我的屏幕激活后的样子。

enter image description here

为什么这没有按预期工作?

编辑: View 也没有变暗

最佳答案

我终于明白了。 UISearchController 需要分配给一个类变量,这样编译器就不会处理它。

@search_controller = UISearchController.alloc
.initWithSearchResultsController(nil)
@search_controller.searchBar.sizeToFit
@search_controller.searchBar.delegate = self

table_header_view @search_controller.searchBar

希望这对以后的人有帮助,这样他们就不必浪费时间思考为什么它不起作用。

关于ios - UISearchController 搜索栏不隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088343/

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