Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when dismissing view controller

Getting an error when dismissing a view controller, not seen anything like it before, and not much about it on the internet.

heres the error: * Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit/UIKit-2903.2/Keyboard/UIKeyboardTaskQueue.m:368

a bit of background, i dismiss the view controller after saving some data. the data saves successfully, every time. also, i recently changed the date saving code to run on the main thread for this one method, as i was having some issues saving in the background.

any ideas why this is happening?

Thanks in advance.

like image 306
Nick Farrant Avatar asked Nov 16 '13 16:11

Nick Farrant


3 Answers

I recieved this error when I was calling -presentViewController:animated:completion: on a thread that was not the main thread (from a callback in a network request). The solution is to dispatch your calls to present and dismiss view controllers to the main thread:

dispatch_async(dispatch_get_main_queue(), ^{
    //Code that presents or dismisses a view controller here
});
like image 112
Simon Goldeen Avatar answered Oct 13 '22 20:10

Simon Goldeen


I had the same problem while calling the camera view

Swift syntax for the same problem:

dispatch_async(dispatch_get_main_queue(), { 
    //Code that presents or dismisses a view controller here  
    self.presentViewController(imagePicker, animated: true, completion: nil)
})
like image 30
Esqarrouth Avatar answered Oct 13 '22 21:10

Esqarrouth


Make sure to dismiss the view controller from the presenting view.

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.

like image 23
EliGreenfeld Avatar answered Oct 13 '22 19:10

EliGreenfeld