4

I have UIPageViewController with one of its view controllers being a UITableViewController. Each UITableViewCell can collapse/expand to hide/show a nested table view. Whether or not any cells are expanded, I get this error sometimes when I scroll up and down in the 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) 

I am very baffled as to why I'm getting this error. I'm wondering if the the UIScrollView of my outer UITableView is conflicting with the UIScrollView of my UIPageViewController, although I only get this error sometimes.

I looked up this error on the Internet and I have only found a few mentions of it, so any help or advice would be greatly appreciated. Thanks.

EDIT: Sorry for not including this earlier, but the UIPageViewController has horizontal navigation.

Rafi
  • 1,902
  • 3
  • 24
  • 46

2 Answers2

3

Here is my idea of how to deal with this problem.

  1. Disable user interaction with UIPageViewController completely using userinteractionenabled = NO
  2. Add Pan gesture recogniser to the UIView
  3. Then determine the direction of Pan and programmatically change UIPageViewController page

Add Pan Gesture

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

Handle Pan

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

Here is how you can change UIPageViewController page programatically

Hope this helps. Cheers!!

Community
  • 1
  • 1
Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
  • 1
    I have a reference to the `UIPageViewController`'s `UIScrollView`, but how do I tell it to start scrolling programmatically from that function? I'm think that in your if and else statements I should plug in this code: [self._scrollView.delegate scrollViewDidScroll:self._scrollView]; – Rafi Aug 13 '15 at 02:33
  • Since user interaction is disabled, I'm assuming this would work since I'm programmatically telling the scroll view to scroll. Please correct me if I'm wrong. – Rafi Aug 13 '15 at 02:35
  • You should not change anything with scrollview, just write code to change the pageviews pages. Like some function like `goToNextPage` or `goToPreviousPage` – Ganesh Somani Aug 13 '15 at 03:35
  • Sorry I don't know know why I didn't see this yesterday. I'll try this right now. – Rafi Aug 13 '15 at 19:14
1

I ended up solving the bug my own way, luckily. Apparently, Apple told me that the UIScrollView in the UIPageViewController and the one in the UITableViewController were conflicting, causing this bug.

All I did was put a UIPanGestureRecognizer on the whole view, and whenever the user scrolls up or down, the UIScrollView in the UIPageViewController is disabled, allowing the user to scroll through the UITableView without conflicts or crashing. When the user stop scrolling up or down, the UIScrollView of the UIPageViewController is re-enabled.

Frustrated that I didn't come up with this solution earlier, but oh well!

Whoever runs into the same problem and his still confused as the how I did my solution, please comment below and I will post my code fix.

Rafi
  • 1,902
  • 3
  • 24
  • 46
  • Hello, could you please post your code how you fixed it? Thanks:) – Patrik Vaberer Jan 07 '16 at 10:29
  • Hi vaberer. I feel your frustration in case you're randomly getting this bug as well. How often are you getting it? Can you describe the blueprint of your app and tell me when the bug is happening? You can post a question on this site, link it to me in these comments, and I can answer the question for you. The biggest reason is that this site does not like when we have prolonged conversations in the comments. Thanks. – Rafi Jan 07 '16 at 18:23