Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate states in queue'

I'm working on a project that use UISlideViewController. I know that this may be a duplicate question but non of the posts before about this topic helped me. I have a specific problem, as I managed to understand. My app crashes on this block. I have read before, it's important to put all work with the UI in the main thread. This is the code:

pageViewController.setViewControllers([viewController],
                    direction: direction,
                    animated: animated,
                    completion: { completed in
                        dispatch_async(dispatch_get_main_queue()) {
 ...

The error that I get is next:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate states in queue'
*** First throw call stack:
(0x183fd1900 0x18363ff80 0x183fd17d0 0x18494499c 0x1894dc9f4 0x1894dcdec...)

Testing it further I also get this error on the same line of code:

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UITableView: 0x12744aa00;
frame = (0 0; 375 515);
    clipsToBounds = YES; autoresize = W+H; 
    gestureRecognizers = <NSArray: 0x12836cf60>; 
    layer = <CALayer: 0x1286226b0>;
    contentOffset: {0, 0}; contentSize: {375, 291}>'

The bug is very hard to reproduce. One literally needs to touch and scroll multiple times on UIPageViewController to get this crash.
Thanks for your time and help.

like image 639
MattCodes Avatar asked Feb 04 '16 08:02

MattCodes


1 Answers

You should put the setViewControllers:direction:animated:completion: code inside of a dispatch_async block. It worked for me. https://stackoverflow.com/a/24749239

like image 115
BadCode Avatar answered Oct 24 '22 05:10

BadCode