【问题标题】:NavigationItem + UISearchBar with SwiftNavigationItem + UISearchBar 与 Swift
【发布时间】:2015-04-09 15:35:17
【问题描述】:

我正在尝试添加一个 UISearchBar,以便在我单击 m 导航栏中的左侧导航项时调用。

就像这样(图 1): http://i.stack.imgur.com/N4tF7.png

点击按钮后(图 2) http://i.stack.imgur.com/nWNCB.png

我试过这种方法:

    @IBAction func searchController2(sender: AnyObject) {
    searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.sizeToFit()
    tableView.tableHeaderView = searchController.searchBar
    definesPresentationContext = true
    }

但问题是,当我点击我的按钮时,在我的导航栏和我的tableview之间创建了一个搜索栏,我只想直接调用图像编号2的效果。

这正是我想要的,但我不知道如何将其转换为 swift :

How to Show and Hide UISearchDisplayController's UISearchBar

【问题讨论】:

    标签: swift uisearchbar uinavigationitem


    【解决方案1】:

    如果您使用的是 UINavigationController,则可以使用 navigationItem 的标题视图。

    navigationItem.titleView = searchController.searchBar

    【讨论】:

      猜你喜欢
      • 2016-08-19
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      相关资源
      最近更新 更多