【发布时间】:2018-07-18 12:54:45
【问题描述】:
我遇到了导航栏的问题。我在 navigationItem 的搜索控制器中添加了searchController。
查看以下链接中的图片: navigation bar issue
步骤:
1) 我在表格视图中有数据,当我单击单元格时,它会打开带有自定义导航视图的详细信息屏幕。这工作正常。 (默认导航栏隐藏)
2) 现在,我点击了搜索栏,然后点击了表格视图单元格。它向我显示默认导航栏到详细信息屏幕。我不想显示默认导航栏。
我为实现搜索控制器而编写的代码如下:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
searchController.searchBar.tintColor = .white
searchController.searchBar.barTintColor = .white
if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
self.navigationItem.searchController = self.searchController
definesPresentationContext = true
下面是在 didSelect 方法中隐藏导航栏的代码:
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
【问题讨论】:
-
你是如何隐藏导航栏的?
tableView(_ tableView: didSelectRowAt indexPath: )的代码是什么? -
@zero3nna,请看我的更新问题,我确实添加了隐藏导航栏的代码。
标签: ios swift uinavigationbar uisearchcontroller