iOS - UIPageViewController 'Failed to determine navigation direction'

iOS - UIPageViewController 'Failed to determine navigation direction'

我有 UIPageViewController,其中一个视图控制器是 UITableViewController。每个 UITableViewCell 可以 collapse/expand 到 hide/show 一个嵌套的 table 视图。无论是否展开任何单元格,当我在 UITableView:

中上下滚动时,有时都会出现此错误
2015-08-12 20:11:15.184 MyApp[4506:172368] *** Assertion failure in -[_UIQueuingScrollView _didEndDraggingManualScroll], /SourceCache/UIKit_Sim/UIKit-3347.44.2/_UIQueuingScrollView.m:861
2015-08-12 20:11:15.261 MyApp[4506:172368] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to determine navigation direction'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d52bc65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010c94cbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010d52baca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010b00b98f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   UIKit                               0x000000010ba257a2 -[_UIQueuingScrollView _didEndDraggingManualScroll] + 151
    5   UIKit                               0x000000010ba2147d -[_UIQueuingScrollView _scrollViewDidEndDraggingWithDeceleration:] + 40
    6   UIKit                               0x000000010b49f8d0 -[UIScrollView _endPanNormal:] + 1415
    7   UIKit                               0x000000010b4a0ddc -[UIScrollView handlePan:] + 98
    8   UIKit                               0x000000010b7be656 _UIGestureRecognizerSendActions + 262
    9   UIKit                               0x000000010b7bd2f9 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
    10  UIKit                               0x000000010b7c1f16 ___UIGestureRecognizerUpdate_block_invoke662 + 51
    11  UIKit                               0x000000010b7c1e12 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
    12  UIKit                               0x000000010b7b7e8d _UIGestureRecognizerUpdate + 2796
    13  UIKit                               0x000000010b45b646 -[UIWindow _sendGesturesForEvent:] + 1041
    14  UIKit                               0x000000010b45c272 -[UIWindow sendEvent:] + 666
    15  UIKit                               0x000000010b422541 -[UIApplication sendEvent:] + 246
    16  UIKit                               0x000000010b42fcdc _UIApplicationHandleEventFromQueueEvent + 18265
    17  UIKit                               0x000000010b40a59c _UIApplicationHandleEventQueue + 2066
    18  CoreFoundation                      0x000000010d45f431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    19  CoreFoundation                      0x000000010d4552fd __CFRunLoopDoSources0 + 269
    20  CoreFoundation                      0x000000010d454934 __CFRunLoopRun + 868
    21  CoreFoundation                      0x000000010d454366 CFRunLoopRunSpecific + 470
    22  GraphicsServices                    0x0000000110821a3e GSEventRunModal + 161
    23  UIKit                               0x000000010b40d8c0 UIApplicationMain + 1282
    24  MyApp                               0x000000010aad6eef main + 111
    25  libdyld.dylib                       0x000000010e2bc145 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我很困惑为什么会收到此错误。我想知道我的外部 UITableViewUIScrollView 是否与我的 UIPageViewControllerUIScrollView 冲突,尽管我有时只会收到此错误。

我在 Internet 上查找了这个错误,但只找到了一些提及它的地方,因此非常感谢任何帮助或建议。谢谢。

编辑:很抱歉之前没有包括这个,但是 UIPageViewController 有水平导航。

这是我对如何处理这个问题的想法。

  1. 使用 userinteractionenabled = NO
  2. 完全禁用用户与 UIPageViewController 的交互
  3. 向 UIView 添加平移手势识别器
  4. 然后判断Pan方向,编程改变UIPageViewController页面

添加平移手势

   UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];

手柄盘

    - (void)panRecognized:(UIPanGestureRecognizer *)rec
    {
       CGPoint vel = [rec velocityInView:self.view];
       if (vel.x > 0)
       {
           // user dragged towards the right
           [self goToNextPage];
       }
       else
       {
           // user dragged towards the left
           [self goToPrevPage];
       }
    }

这里是你如何可以change UIPageViewController page programatically

希望这对您有所帮助。干杯!!

幸运的是,我最终以自己的方式解决了这个错误。显然,Apple 告诉我 UIPageViewController 中的 UIScrollViewUITableViewController 中的 UIScrollView 存在冲突,从而导致此错误。

我所做的只是在整个视图上放置一个 UIPanGestureRecognizer,每当用户向上或向下滚动时,UIPageViewController 中的 UIScrollView 被禁用,允许用户滚动 UITableView 没有冲突或崩溃。当用户停止向上或向下滚动时,重新启用 UIPageViewControllerUIScrollView

很沮丧我没有早点想出这个解决方案,但是哦好吧!

遇到同样问题但仍然对我的解决方案感到困惑的人,请在下面发表评论,我将 post 我的代码修复。