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). They both don't work. In fact, whenever I click on the cells the instead of presenting the view controller for the selected cell all that happens is that I get the following warning on the console :


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


However, initially, before any character is typed, the tableView is populated with all the possible groups. Clicking on one of those cells works and corrently links you to the dynamic view controller for that group.


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{      
          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) 
     }
 }



If you have any idea why this is happening it would be very appreciated if you could let me know. I've been stuck trying to figure this out for a while now!


Thanks

The error message is commenting on your attempt to do this:

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

It is telling you that "self" (which it is referring to as "MyProject.SearchPage") is already presenting a view controller (your UISearchController) and therefore it cannot present the view controller you want it to present, which you call "vc" with the identifier "ProfileView".

When the error is not presented that is because it is not, at that time, presenting the UISearchController.


A view controller can present only one view controller, I believe. I think you have two choices - dismiss the UISearchController before presenting as you are or else try to get the UISearchController to present the new view controller. You may find that this method is a God Sent in these circumstances:


-(UIViewController *)theParentVC{
    UIViewController* parentController =self;
    while( parentController.presentedViewController &&
          parentController != parentController.presentedViewController ){
        parentController = parentController.presentedViewController;
    }
    return parentController;
}
Warning: Attempt to present View Controller on * which is already presenting &lt;UISearchController: 0x142a1f7c0&gt;
 
 
Q