本文介绍了警告:尝试在*上已显示< UISearchController:0x142a1f7c0>的视图控制器上显示View Controller.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用UISearchControllerUITableView制作了一个视图控制器.您可以从搜索范围按钮中选择两种不同类型的搜索:组和人员.两种搜索均有效,并在表上显示结果.但是,如果单击每个单元格,它们应将您定向到不同的动态页面(动态组页面或动态人员个人资料页面).一种用于组,而一种用于配置文件则无效.意思是,每当我从获得的结果中单击一个人员单元格时,都不会发生任何事情,并且会在控制台上打印以下警告:

I made a view controller with a UISearchController and a UITableView . There are two different kind of search you can select from the search scope buttons : groups and people. Both searches work and show results on the table. However, if you click on each cell they should direct you to different dynamic pages (a dynamic group page or a dynamic person profile page). The one for groups works, while the one for profiles doesn't. Meaning whenever I click on the a person cell from the results that I got, nothing happens and I get the following warning printed on the console :

Warning: Attempt to present <MyProject.profileView: 0x13e9df000>  on <MyProject.SearchPage: 0x142a1d8f0> which is already presenting <UISearchController: 0x142a1f7c0>

如果您知道为什么会发生这种情况,请让我知道.

If you have any idea why this could be happening it'd be really appreciated if you could let me know.

这是将单元格链接到不同视图控制器的函数:

EDIT : Here's the function that should link the cell to the different view controllers :

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        if self.searchForGroups {

            let detailCell:PFObject = self.filteredGroups.objectAtIndex(indexPath.row) as! PFObject

            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("DynamicCellView") as! DynamicCellView

            vc.GroupId = detailCell.objectId!

            self.presentViewController(vc, animated: false, completion: nil)

        }else{
            //Link to use profile
            let user = self.peopleResults[indexPath.row]
            let vc = self.storyboard!.instantiateViewControllerWithIdentifier("ProfileView") as! profileView
            vc.profileId = user.objectId!
            self.presentViewController(vc, animated: true, completion: nil)
        }
    }

推荐答案

我也有同样的警告,这对我来说已经解决了.您需要停止显示搜索控制器,以便在离开视图时可以显示其他控制器.

I was having the same warning and this fixed it for me. You need to stop presenting the search controller so you can present other controller while you are leaving the view.

         override func viewDidDisappear(_ animated: Bool) {

                if SearchController.isActive == true {

                          SearchController.isActive = false

                 }
          } 

这篇关于警告:尝试在*上已显示&lt; UISearchController:0x142a1f7c0&gt;的视图控制器上显示View Controller.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:07