【问题标题】:Invalid parameter exception thrown by _UIQueuingScrollView_UIQueuingScrollView 抛出的无效参数异常
【发布时间】:2013-11-29 00:53:09
【问题描述】:

包含嵌入在 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

是否有人已经看到或知道原因可能是什么?

【问题讨论】:

  • 遇到这个问题后,我发现最好的解决方案是自己做动画UIView transitionWithView:toView:..。我认为这是 iOS 的一个真正的错误,没有找到堆栈溢出的解决方案对我有用(目前)。

标签: ios cocoa-touch uiscrollview ios7 uikit


【解决方案1】:

我在嵌入 UIPageViewController 的 UIViewController 中遇到了同样的错误。就我而言,我意识到我的子控制器已经覆盖了viewWillAppearviewDidAppear,而没有调用super。虽然我只能猜测细节,但这样做可能会弄乱视图管理是有道理的。添加super 调用使问题消失。

【讨论】:

  • 谢谢。但这不是我的问题。再次发生时我会再次分析。
【解决方案2】:

编辑:在使用此修复程序更多时间后,我有时仍然可以看到该错误,因此这不是完整的修复程序(嗯……它总是一种黑客行为)。找到后我会更新实际的解决方案。


我在使用 UIPageViewController 时遇到了同样的错误。经过数小时调试问题,我发现原因是在 UIPageViewController 的 setViewControllers:direction:animated:completion: 的完成处理程序中使用 UIView 动画。

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

【讨论】:

  • 老兄,这条评论太棒了。
  • 顺便说一句,在我的情况下,“完成块”并不是真正的问题......我正在执行动画视图确实出现了,(可能在动画完成之前被调用);)
  • 你有没有得到 UIPageViewController 崩溃的完整解决方案。
  • 惊人的节省时间。我正在为一些集合视图单元格设置动画并收到此错误。在调度中包装动画,它就消失了。
  • 使用完成处理程序,即使是与 UI 无关的事情也对我不利。
【解决方案3】:

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

__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
    }
}];

【讨论】:

  • 你能帮我解决这个错误吗?我已经尝试了每个人的解决方案..但它不起作用断言失败 -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/ _UIQueuingScrollView.m:377 *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效参数不满足:[views count] == 3”我使用了 LTPageManger Github 项目
  • 好的,我最终得到 pageView.userInteractionEnabled 在 vi​​ewWillAppear、viewDidAppear 和 viewWillDisappear 中是和否。感谢您的提示。
【解决方案4】:

只需确保您没有在要返回的控制器中的 viewDidAppear 中执行任何动画。或者,如果您必须在视图出现后延迟一段时间后再执行此操作。

【讨论】:

  • 对我来说,在viewDidAppear 中使用input.becomeFirstResponder() 时会出现此错误。动画是由键盘的出现引起的。
  • @mixable - 可能有点晚了,但如果你将 input.becomeFirstResponder 包装在主线程的调度块中,它可能会为你解决问题 - 它对我有用。 [self.pageVC setViewControllers:@[self.currentVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) { dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.currentVC.textField becomeFirstResponder]; }); }];
【解决方案5】:

在我的情况下,问题在于UIPageViewControllerDelegate的实现:

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

主队列上的dispatch_async 解决了这个问题

【讨论】:

    【解决方案6】:

    我使用带有点的 UIPageViewController。用户在点上滑动后,委托 didFinishAnimating 被调用,我触发了其他动画,然后它崩溃了。但只有当用户在点上滑动时才会发生这种情况。

    - (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];
            })
        }
    }
    

    【讨论】:

    • 这应该是修复崩溃的解决方案吗?你能解释一下吗?
    • 它修复了崩溃。但我不知道为什么必须再次分派到主队列,即使它已经在主线程中。
    • 我有类似的代码在pageViewController: didFinishAnimation委托方法中触发了一些动画,并且在切换页面时随机崩溃。将动画调用放入 DispatchQueue.main.async 调用修复崩溃。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 2021-04-15
    • 2014-02-23
    • 2016-11-07
    • 2012-10-12
    • 2019-11-21
    • 1970-01-01
    相关资源
    最近更新 更多