Getting black screen on using tab bar while searching using SearchController(使用 SearchController 搜索时使用标签栏出现黑屏)

本文介绍了使用 SearchController 搜索时使用标签栏出现黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在导航控制器中嵌入标签栏控制器的应用.该应用程序有 2 个选项卡,第一个(搜索)有一个使用 UISearchController 实现的搜索栏.如果我在搜索时从这个选项卡切换到另一个选项卡(下载),那么会发生两件事 -

  • 第二个标签(下载)中的导航栏消失
  • 当我回到第一个选项卡(搜索)时,它显示黑屏

我已经使用情节提要完成了所有这些工作.

这是我的 SearchViewController

导入 UIKit进口阿拉莫火导入 SwiftyJSON类 ViewController:UIViewController、UITableViewDelegate、UITableViewDataSource、UISearchResultsUpdating、UISearchBarDelegate{//MARK:变量var 论文 = [论文]()var filteredPapers = [论文]()让 searchController = UISearchController(searchResultsController: nil)//MARK:奥特莱斯@IBOutlet 弱 var activityIndi​​cator:UIActivityIndi​​catorView!@IBOutlet var 表:UITableView!@IBOutlet 弱变量 loadingMessageLabel:UILabel!@IBOutlet 弱 var retryButton:UIButton!//MARK:动作@IBAction func retryButton(sender: UIButton) {self.loadingMessageLabel.hidden = falseself.loadingMessageLabel.text = "当卫星移动到位时......"self.activityIndi​​cator.hidden = falseself.activityIndi​​cator.startAnimating()self.retryButton.hidden = trueself.getPapersData()}//MARK: 表格视图func tableView(tableView: UITableView, numberOfRowsInSection section: Int) ->诠释{//如果处于搜索模式,则返回结果个数,否则返回总数//如果 searchController.active &&searchController.searchBar.text != "" {如果 searchController.active {返回filteredPapers.count}返回文件.count}func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {让纸:纸//如果 searchController.active &&searchController.searchBar.text != "" {如果 searchController.active {纸=过滤纸[indexPath.row]} 别的 {论文 = 论文[indexPath.row]}如果让 cell = self.table.dequeueReusableCellWithIdentifier("Cell") as?PapersTableCell {cell.initCell(paper.name,详细信息:paper.detail)打印(单元格)返回单元格}返回 PapersTableCell()}func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {}func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) ->[UITableViewRowAction]?{let downloadButton = UITableViewRowAction(style: .Normal, title: "Download") { action, index invar url = String(self.papers[indexPath.row].url)url = url.stringByReplacingOccurrencesOfString(" ", withString: "%20")打印(网址)让目的地 = Alamofire.Request.suggestedDownloadDestination(目录:.DocumentDirectory,域:.UserDomainMask)//单元格中的微调器//var selectCell = self.table.cellForRowAtIndexPath(indexPath) as?论文表细胞//selectCell!.downloadSpinner.hidden = false//关闭下载按钮self.table.editing = falseAlamofire.download(.GET, url, destination: destination).response { _, _, _, 错误如果让错误=错误{print("失败并出现错误:(error)")} 别的 {print("文件下载成功")}//selectCell?.downloadSpinner.hidden = true}}downloadButton.backgroundColor = UIColor(red:0.30, green:0.85, blue:0.39, alpha:1.0)返回 [下载按钮]}func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) ->布尔 {//您希望动作出现的单元格必须是可编辑的返回真}func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {//你也需要实现这个方法,否则你不能滑动显示动作}//标记:搜索func filterContentForSearchText(searchText: String, scope: String = "All") {过滤纸=论文.过滤器{纸在让 categoryMatch = (scope == "All") ||(paper.exam == 范围)返回类别匹配&&paper.name.lowercaseString.containsString(searchText.lowercaseString)}table.reloadData()}func updateSearchResultsForSearchController(searchController: UISearchController) {让 searchBar = searchController.searchBar让范围 = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]filterContentForSearchText(searchController.searchBar.text!,范围:范围)}func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {filterContentForSearchText(searchBar.text!, scope: searchBar.scopeButtonTitles![selectedScope])}//标记:默认值覆盖 func viewDidLoad() {super.viewDidLoad()self.getPapersData()searchController.searchResultsUpdater = 自我searchController.dimsBackgroundDuringPresentation = false定义PresentationContext = truetable.tableHeaderView = searchController.searchBarsearchController.searchBar.scopeButtonTitles = [全部",ST1",ST2",PUT",UT"]searchController.searchBar.delegate = selfactivityIndi​​cator.startAnimating()}覆盖 func viewWillDisappear(动画:布尔){//如果 searchController.active {self.searchController.resignFirstResponder()/