我的应用程序包含嵌入在UIPageViewController中的UITableViewController不时引发此异常:

Invalid parameter not satisfying: [views count] == 3

后退,后退:

* thread #1: tid = 0x6239fa, 0x03d1d88a libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread, stop reason = breakpoint 25.3
    frame #0: 0x03d1d88a libobjc.A.dylib`objc_exception_throw
    frame #1: 0x0404f448 CoreFoundation`+[NSException raise:format:arguments:] + 136
    frame #2: 0x03428fee Foundation`-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    frame #3: 0x01e7c535 UIKit`-[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:] + 185
    frame #4: 0x01e800ca UIKit`-[_UIQueuingScrollView _didScrollWithAnimation:force:] + 1231
    frame #5: 0x01e7bb57 UIKit`-[_UIQueuingScrollView _scrollViewAnimationEnded:finished:] + 104
    frame #6: 0x0190583c UIKit`-[UIScrollView(UIScrollViewInternal) animator:stopAnimation:fraction:] + 62
    frame #7: 0x0197096e UIKit`-[UIAnimator stopAnimation:] + 533
    frame #8: 0x0197100a UIKit`-[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 325
    frame #9: 0x01970b76 UIKit`-[UIAnimator(Static) _LCDHeartbeatCallback:] + 67
    frame #10: 0x01663b8a QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 48
    frame #11: 0x01663a46 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 310
    frame #12: 0x01663f6b QuartzCore`CA::Display::TimerDisplayLink::callback(__CFRunLoopTimer*, void*) + 123
    frame #13: 0x0400dbd6 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
    frame #14: 0x0400d5bd CoreFoundation`__CFRunLoopDoTimer + 1181
    frame #15: 0x03ff5628 CoreFoundation`__CFRunLoopRun + 1816
    frame #16: 0x03ff4ac3 CoreFoundation`CFRunLoopRunSpecific + 467
    frame #17: 0x03ff48db CoreFoundation`CFRunLoopRunInMode + 123
    frame #18: 0x0533b9e2 GraphicsServices`GSEventRunModal + 192
    frame #19: 0x0533b809 GraphicsServices`GSEventRun + 104
    frame #20: 0x01874d3b UIKit`UIApplicationMain + 1225

有没有人已经看到了这一点,或者知道原因可能是什么?

有帮助吗?

解决方案

编辑:在使用此修复后更多的时间,我仍然可以看到错误的错误,所以这不是完整的修复(嗯......它总是一个黑客)。我会发现它会用实际解决方案更新。


我已经遇到了使用uipageViewController相同的错误。完成后处理问题后,我发现原因在于UIVAGEVIEWController的SetViewController的完成处理程序内使用UIView动画:方向:动画:完成:。

我不知道为什么在该阶段动画导致断言错误(我没有动画UIPageViewController或其子视图控制器),但在主队列上用Dispatch_Async包装代码块解决问题并停止崩溃并停止崩溃。

其他提示

我在尝试以编程方式转换到新页面时看到了此崩溃。对我有意义的答案是不允许他们在过渡期间触摸页面视图。

__block UIView *pageView = pageViewController.view;

// Disable page view to not allow the user to interrupt the page view animation and cause crash
pageView.userInteractionEnabled = NO;

[pageViewController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
    if (finished) {
        pageView.userInteractionEnabled = YES; // re-enable
    }
}];
.

只需确保您无法在要返回的控制器中的ViewDideapear中执行任何动画。或者如果您必须在某些延迟后会这样做,一旦视图出现。

我使用带有点的UIPageViewController。在用户滑动点后,Didfinishanimation的委托称为并触发其他动画,然后崩溃。但只有在用户在点上滑动时才发生。

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
{
    if (completed && finished)
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self animateSomeView];
        })
    }
}
.

我在uipageviewcontroller中嵌入的UIViewController中遇到了同样的错误。在我的情况下,我意识到我的子控制器已复盖 viewWillAppearviewDidAppear 没有打电话到 super.虽然我只能猜测细节,但这样做可能会弄乱视图管理是有道理的。添加 super 打来的电话使问题消失了.

在我的情况下,问题是在实施 UIPageViewControllerDelegate:

我更新约束在 pageViewController(_ pageViewController:, didFinishAnimating:, previousViewControllers:, transitionCompleted:)

dispatch_async 在主队列上解决此问题

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top