当viewWillAppear时,ECSlidingViewController错误(对象不能为nil)

时间:2013-09-28 00:40:50

标签: iphone ios objective-c uinavigationcontroller ecslidingviewcontroller

在我的应用程序中,我有一个连接到另一个viewController(根控制器)的导航控制器。在我的项目中,我导入了ECSlidingViewController.h和.m。在将用作右侧菜单(listViewController.h)的viewController中,我导入了ECSlidingViewController.h,并在viewDidLoad中执行了此操作:

[super viewDidLoad];
    self.peekLeftAmount = 40.0f;
    [self.slidingViewController setAnchorLeftPeekAmount:self.peekLeftAmount];
    self.slidingViewController.underRightWidthLayout = ECVariableRevealWidth;

在navigationController类中,我做了这个(在导入ECSlidingViewController.h和listViewController.h之后):

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (![self.slidingViewController.underRightViewController isKindOfClass:[ListViewController class]]) {
        self.slidingViewController.underRightViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"ListStore"];
    }

    [self.view addGestureRecognizer:self.slidingViewController.panGesture];
}

但是当我运行应用程序时,当我到达代码行[self.view addGestureRecognizer:self.slidingViewController.panGesture];时,应用程序崩溃了,并且给了我以下错误:

2013-09-28 01:59:55.629 Myapp[2627:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x024595e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01a6f8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x0240bc3c -[__NSArrayM insertObject:atIndex:] + 844
    3   CoreFoundation                      0x0240b8e0 -[__NSArrayM addObject:] + 64
    4   UIKit                               0x0063f497 -[UIView(UIViewGestures) addGestureRecognizer:] + 208
    5   Myapp                              0x0001a934 -[MainNavigationController viewWillAppear:] + 564
    6   UIKit                               0x006ec28a -[UIViewController _setViewAppearState:isAnimating:] + 419
    7   UIKit                               0x006ec798 -[UIViewController __viewWillAppear:] + 114
    8   UIKit                               0x006fd310 -[UIViewController(UIContainerViewControllerProtectedMethods) beginAppearanceTransition:animated:] + 199
    9   UIKit                               0x0097d627 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 6236
    10  UIKit                               0x006f478c -[UIViewController presentViewController:withTransition:completion:] + 6433
    11  UIKit                               0x006f4caf -[UIViewController presentViewController:animated:completion:] + 130
    12  Myapp                              0x00017447 -[SplashScreenViewController viewDidAppear:] + 839
    13  UIKit                               0x006ec2d8 -[UIViewController _setViewAppearState:isAnimating:] + 497
    14  UIKit                               0x006ec867 -[UIViewController __viewDidAppear:] + 146
    15  UIKit                               0x006ee22f __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 44
    16  UIKit                               0x006ecbfa -[UIViewController _executeAfterAppearanceBlock] + 63
    17  UIKit                               0x005f1d59 ___afterCACommitHandler_block_invoke_2 + 33
    18  UIKit                               0x005f1cde _applyBlockToCFArrayCopiedToStack + 403
    19  UIKit                               0x005f1b2e _afterCACommitHandler + 568
    20  CoreFoundation                      0x0242153e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    21  CoreFoundation                      0x0242148f __CFRunLoopDoObservers + 399
    22  CoreFoundation                      0x023ff3b4 __CFRunLoopRun + 1076
    23  CoreFoundation                      0x023feb33 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x023fe94b CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x032da9d7 GSEventRunModal + 192
    26  GraphicsServices                    0x032da7fe GSEventRun + 104
    27  UIKit                               0x005d594b UIApplicationMain + 1225
    28  Myapp                              0x00002b2b main + 235
    29  libdyld.dylib                       0x01f54725 start + 0
    30  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

拜托,帮助我!

1 个答案:

答案 0 :(得分:1)

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *MainView = [storyBoard instantiateViewControllerWithIdentifier:@"MyMailBox"];
self.slidingViewController.topViewController = MainView;