Search code examples
objective-cuisplitviewcontrollerios8.1

issue with UISplitViewController in iOS 8.1: [UISplitViewController navigationBar]: unrecognized selector sent to instance


Im trying to create a New UISPlitViewController and display it instead of current ViewController, but for some reason it's not working, it says:

-[UISplitViewController navigationBar]: unrecognized selector sent to instance

this is the code

- (IBAction)openDocuments:(id)sender {

    UINavigationController  *leftNavController;
    UINavigationController  *rightNavController;

    MenuDocumentsVC *masterVC           = [self.storyboard instantiateViewControllerWithIdentifier:@"MenuDocumentsVC"];
    masterVC.title                      = @" ";


    ContentDocumentsVC *detailVC           = [self.storyboard instantiateViewControllerWithIdentifier:@"ContentDocumentsVC"];
    detailVC.navigationItem.titleView   = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];

    masterVC.delegate = detailVC;

    leftNavController               = [[UINavigationController alloc] initWithRootViewController:masterVC];
    rightNavController              = [[UINavigationController alloc] initWithRootViewController:detailVC];

    leftNavController.toolbarHidden                 = FALSE;
    rightNavController.toolbarHidden                = FALSE;
    leftNavController.navigationBar.translucent     = FALSE;
    rightNavController.navigationBar.translucent    = FALSE;
    leftNavController.toolbar.translucent           = FALSE;
    rightNavController.toolbar.translucent          = FALSE;


    UISplitViewController   *splitViewController    = [[UISplitViewController alloc] init];
    splitViewController.viewControllers             = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
    splitViewController.delegate                    = (id)detailVC;


    if ([splitViewController respondsToSelector:@selector(setPresentsWithGesture:)]) {
        [splitViewController setPresentsWithGesture:NO];
    }

    splitViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;


    [UIView transitionWithView:self.view.window
                      duration:0.5
                       options:UIViewAnimationOptionCurveEaseOut
                    animations:^{
                        self.view.window.rootViewController      = splitViewController;
                    } completion:^(BOOL finished) {

                    }];   
}

how to make it work properly??

Exception

2015-01-05 11:01:47.402 myapp[3454:607] -[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00
2015-01-05 11:01:47.406 myapp[3454:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00'
*** First throw call stack:
(
    0   CoreFoundation                      0x010a21e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00a718e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0113f243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0109250b ___forwarding___ + 1019
    4   CoreFoundation                      0x010920ee _CF_forwarding_prep_0 + 14
    5   eOpenRoad                           0x00056d7d +[Functions setNavigationBarControllerToHexColor:] + 333
    6   eOpenRoad                           0x0004fa15 -[ContentDocumentsVC viewWillAppear:] + 69
    7   UIKit                               0x0163e04b -[UIViewController _setViewAppearState:isAnimating:] + 448
    8   UIKit                               0x0163e548 -[UIViewController __viewWillAppear:] + 114
    9   UIKit                               0x01660c25 -[UINavigationController _startTransition:fromViewController:toViewController:] + 800
    10  UIKit                               0x016618cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
    11  UIKit                               0x016624e9 -[UINavigationController __viewWillLayoutSubviews] + 57
    12  UIKit                               0x017a30d1 -[UILayoutContainerView layoutSubviews] + 213
    13  UIKit                               0x0158a964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    14  libobjc.A.dylib                     0x00a8382b -[NSObject performSelector:withObject:] + 70
    15  QuartzCore                          0x001ea45a -[CALayer layoutSublayers] + 148
    16  QuartzCore                          0x001de244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    17  QuartzCore                          0x001ea3a5 -[CALayer layoutIfNeeded] + 160
    18  UIKit                               0x0164cae3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
    19  UIKit                               0x01562aa7 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
    20  UIKit                               0x01561646 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
    21  UIKit                               0x01561518 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
    22  UIKit                               0x015615a0 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
    23  UIKit                               0x0156063a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
    24  UIKit                               0x0156059c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
    25  UIKit                               0x015612f3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
    26  UIKit                               0x015648e6 -[UIWindow setDelegate:] + 449
    27  UIKit                               0x0163eb77 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
    28  UIKit                               0x0155a474 -[UIWindow addRootViewControllerViewIfPossible] + 591
    29  UIKit                               0x0155ac84 -[UIWindow setRootViewController:] + 960
    30  eOpenRoad                           0x0005c5ec +[Functions openContentInWindowWithParameters:insideOfNavigationController:] + 7804
    31  eOpenRoad                           0x0001f42b -[ViewController openDocuments:] + 555
    32  libobjc.A.dylib                     0x00a83880 -[NSObject performSelector:withObject:withObject:] + 77
    33  UIKit                               0x0151d3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    34  UIKit                               0x0151d345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    35  UIKit                               0x0161ebd1 -[UIControl sendAction:to:forEvent:] + 66
    36  UIKit                               0x0161efc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    37  UIKit                               0x0161e243 -[UIControl touchesEnded:withEvent:] + 641
    38  UIKit                               0x0155cddd -[UIWindow _sendTouchesForEvent:] + 852
    39  UIKit                               0x0155d9d1 -[UIWindow sendEvent:] + 1117
    40  UIKit                               0x0152f5f2 -[UIApplication sendEvent:] + 242
    41  UIKit                               0x01519353 _UIApplicationHandleEventQueue + 11455
    42  CoreFoundation                      0x0102b77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    43  CoreFoundation                      0x0102b10b __CFRunLoopDoSources0 + 235
    44  CoreFoundation                      0x010481ae __CFRunLoopRun + 910
    45  CoreFoundation                      0x010479d3 CFRunLoopRunSpecific + 467
    46  CoreFoundation                      0x010477eb CFRunLoopRunInMode + 123
    47  GraphicsServices                    0x03ae75ee GSEventRunModal + 192
    48  GraphicsServices                    0x03ae742b GSEventRun + 104
    49  UIKit                               0x0151bf9b UIApplicationMain + 1225
    50  eOpenRoad                           0x00051e3d main + 141
    51  libdyld.dylib                       0x036b76d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Solution

  • From provided log I can say that problem lie in [ContentDocumentsVC viewWillAppear:] where you set color to navigation bar with category method setNavigationBarControllerToHexColor: but looks like you call this method on wrong controller.