Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assertion failure in UIPageViewController

While switching between Tabs too fast in UIPageViewController, App getting crash in line

[UIPageViewController queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:]

with errors Assertion failure and Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view.

Error Log as below

*** Assertion failure in -[UIPageViewController queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:], /SourceCache/UIKit/UIKit-3318.0.1/UIPageViewController.m:1875
2014-09-29 11:34:00.770 Wowcher[193:9460] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No view controller managing visible view <UIView: 0x1783fa80; frame = (0 0; 320 416); autoresize = W+RM+H+BM; layer = <CALayer: 0x17898540>>'
*** First throw call stack:
(0x219fbf87 0x2f15ac77 0x219fbe5d 0x226cb2c9 0x253f9fff 0x2546f8d3 0x2546f6b7 0x2546c2b9 0x254700db 0x25470f97 0x2546d037 0x24ea925f 0x2500a589 0x24ff7eef 0x24ea677d 0x252b8c81 0x24e70105 0x24e6e07f 0x24ea4b6d 0x24ea443d 0x24e7acc5 0x250ee513 0x24e79707 0x219c2807 0x219c1c1b 0x219c0299 0x2190ddb1 0x2190dbc3 0x28c99051 0x24ed9a31 0xd950b 0xca6e0)
libc++abi.dylib: terminating with uncaught exception of type NSException

Thanks in advance

like image 863
Brjv Avatar asked Sep 09 '14 08:09

Brjv


3 Answers

So my solution to this was adding a BOOL which keeps track of my animations state. So before setting the new ViewController, I modify this too:

if (!_transitionInProgress) {
    _transitionInProgress = YES;
    [self.pageController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:^(BOOL finished) {
        _transitionInProgress = !finished;
    }];
}

So I'll wait for my animation to finish before setting a new view controller. In my case, I have a some buttons the user can press in order to switch pages. This also prevents them from going too fast through them so the animations are always smooth and nice

like image 199
Andrei Filip Avatar answered Nov 05 '22 11:11

Andrei Filip


This is a bug in the internal implementation of UIPageViewController in scroll mode. It happens when a transition animation occurs while the page view controller is already animating a transition. What I ended up doing was to block the UI from allowing multiple quick scrolls. I have two buttons, left and right, which make the page view controller scroll to previous or next page controller. I disable the buttons' operation while there is an animation going. The page view controller's delegate tells you all you need to know when to disable the UI's functionality and when to re-enable it, once all animations have stopped.

like image 14
Léo Natan Avatar answered Nov 05 '22 10:11

Léo Natan


I am also facing this problem, but the issue is that I am unable to consistently reproduce the problem, but I can see from the crashlogs that the issue exists.

I have the pageviewcontroller which allows the user to swipe and also the view scrolls programmatically. The app crashes sometimes when you just enter the screen, but in the next attempts it works fine, so its kind of crazy. Even if I put a fix I cant be sure that it works as I am unable to reproduce it. Looks like the below code should fix it (took from Removing a view controller from UIPageViewController) atleast the screen behaves better with this code. I would really appreciate if I can get some methods to inject this crash myself, so that I can verify the fix.

- (void) setViewControllers:(NSArray*)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL))completion {

    if (!animated) {
        [super setViewControllers:viewControllers direction:direction animated:NO completion:completion];
        return;
    }

    [super setViewControllers:viewControllers direction:direction animated:YES completion:^(BOOL finished){

        if (finished) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [super setViewControllers:viewControllers direction:direction animated:NO completion:completion];
            });
        } else {
            if (completion != NULL) {
                completion(finished);
            }
        }
    }];
}
like image 4
anoop4real Avatar answered Nov 05 '22 09:11

anoop4real