gpt4 book ai didi

ios - swift 将搜索栏添加到导航栏

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:52 28 4
gpt4 key购买 nike

我正在尝试将搜索栏添加到导航栏。我已经研究了一下,这是我到目前为止所做的:

问题是使用这段代码 navigationBar 什么都没有出现。

    searchBar = UISearchBar(frame: CGRectMake(0, 0, 320, 44))
searchBar?.delegate = self
searchBar?.showsCancelButton = true


searchController = UISearchDisplayController()
searchController?.delegate = self
searchController?.searchResultsDelegate = self

searchController?.displaysSearchBarInNavigationBar = true

最佳答案

试试这段对我有用的代码:

 lazy   var searchBars:UISearchBar = UISearchBar(frame: CGRectMake(0, 0, 200, 20))

override func viewDidLoad() {
super.viewDidLoad()
var leftNavBarButton = UIBarButtonItem(customView: searchBars)
self.navigationItem.leftBarButtonItem = leftNavBarButton
}

关于ios - swift 将搜索栏添加到导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26384144/

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