Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Attempt to present View Controller on * which is already presenting <UISearchController: 0x142a1f7c0>

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)
        }
    }
like image 773
Giulio Colleluori Avatar asked Nov 29 '22 09:11

Giulio Colleluori


1 Answers

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

                 }
          } 
like image 141
Fidel Avatar answered Feb 07 '23 01:02

Fidel