Search code examples
iosuitableviewxcode7uisearchcontroller

UISearchController - Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress


I have a searchable tableview controller (using UISearchController and an NSFetchedResultsController) which lists rows of items.

It has the user click on an row to select the item, which calls an unwind segue to the previous tableview.

When the user clicks on a row, I want the selected FetchedResultsController object to be sent back to the original tableview controller and populate a field in the original tableview and to dismiss the current searchable tableview controller.

When I click on a row to select the item without searching, it works fine without any warnings.

However, when I search the table and then select from the filtered items I am presented with the following warning:

Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

The unwind segue is wired in the storyboard from the tableview cell to the "Exit" icon on the same tableview controller. Here is the code for the unwind segue:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "myUnwindSegue" {

        let indexPath = tableView.indexPathForSelectedRow
        selectedAirfield = frc.objectAtIndexPath(indexPath!) as? Airfields
        self.navigationController?.popViewControllerAnimated(true)

    }
}

I have also tried:

if !self.isBeingDismissed() {
    self.navigationController?.popViewControllerAnimated(true)
}

But this gives me the same warning as above.

I have also tried:

self.dismissViewControllerAnimated(true, completion: nil)

But this only gets me back to the current tableview and does not get me back to the previous tableview controller and gives me the following warning:

popToViewController:transition: called on while an existing transition or presentation is occurring; the navigation stack will not be updated.

I have also tried disabling the animation on the segue to the searchable tableview controller but this has no effect.

I have also tried placing:

self.searchController?.loadViewIfNeeded()

in viewDidLoad and also tried:

 deinit{
    if let superView = resultSearchController.view.superview {
        superView.removeFromSuperview()
    }
 }

Both these do not solve the problem.

To reiterate, it only happens when selecting the search results and works perfectly when selecting the unfiltered tableview rows.

I am on Xcode 7.2.1.

Any help appreciated.


Solution

  • OK I found the problem and it may help someone else.

    I had the following in the didSelectRowAtIndexPath method:

    self.resultSearchController.active = false
    

    So, as I was dismissing the view by selecting the row, I was trying to deactivate the UISearchController which obviously involved an animation/presentation

    By deleting this line, the warnings have ceased.