popToRootViewcontroller被推送到同一个视图,当点击推回视图时崩溃

时间:2015-02-22 04:01:17

标签: ios objective-c pushviewcontroller poptoviewcontroller

目前我有一个UITableViewController和一系列Tabs。一旦收到通知,我就会执行本地警报的显示,当它点击时我会向用户显示当前的通话。我的道路是。

UITableViewController>客房>聊天对话

问题是。我想在[nav popViewControllerAnimated:NO];因为它可以很好地将一个会话中的同一个VC推送到另一个会话。但是当我按下按钮时它会崩溃。它从rootViewControler执行推送,但在我回击时无法找到通往Rooms的方式。

CODE:

- (void)DisplayNewMessage:(NSNotification *) notification {

    NSDictionary* userInfo = notification.userInfo;

    UITabBarController *tab = self;
    [tab setSelectedIndex:2];
    UINavigationController *nav = tab.viewControllers[2];
    RoomListTableView *chatWindow = nav.viewControllers[0];

    chatWindow.user_reciever = userInfo[@"user_reciever"];
    chatWindow.roomid = userInfo[@"room"];
    chatWindow.user_sender = userInfo[@"user_sender"];

    NSLog(@"ROOM_ID_WEB: %@", userInfo[@"room"]);

    if ([nav.topViewController isKindOfClass:[chatVC class]]) {

        chatVC *conversationVC = (chatVC *) nav.topViewController;

        if (![conversationVC.roomid isEqualToString:userInfo[@"room"]]) {

            [nav popViewControllerAnimated:NO];
            [chatWindow performSegueWithIdentifier:@"push_conversation" sender:self]; 
        }
    }

    if ([nav.topViewController isKindOfClass:[RoomListTableView class]]) {

        [chatWindow performSegueWithIdentifier:@"push_conversation" sender:self]; // push_conversation
    }
}

堆栈追踪:

2015-02-21 23:19:12.992 mobile-app[1429:91432] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: section (0) beyond bounds (0).'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001134f1f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000112dedbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001134f1e6d +[NSException raise:format:] + 205
    3   UIKit                               0x000000011177ba8f -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 429
    4   UIKit                               0x000000011177c94a -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 33
    5   mobile-app                          0x000000010de3341d -[chatVC viewWillAppear:] + 1889
    6   UIKit                               0x00000001117bf821 -[UIViewController _setViewAppearState:isAnimating:] + 487
    7   UIKit                               0x00000001117df605 -[UINavigationController _startCustomTransition:] + 887
    8   UIKit                               0x00000001117eb3fe -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    9   UIKit                               0x00000001117ebf47 -[UINavigationController __viewWillLayoutSubviews] + 43
    10  UIKit                               0x0000000111931509 -[UILayoutContainerView layoutSubviews] + 202
    11  UIKit                               0x000000011170f973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
    12  QuartzCore                          0x0000000110244de8 -[CALayer layoutSublayers] + 150
    13  QuartzCore                          0x0000000110239a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    14  QuartzCore                          0x000000011023987e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    15  QuartzCore                          0x00000001101a763e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    16  QuartzCore                          0x00000001101a874a _ZN2CA11Transaction6commitEv + 390
    17  QuartzCore                          0x00000001101a8db5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    18  CoreFoundation                      0x0000000113426dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    19  CoreFoundation                      0x0000000113426d20 __CFRunLoopDoObservers + 368
    20  CoreFoundation                      0x000000011341cb53 __CFRunLoopRun + 1123
    21  CoreFoundation                      0x000000011341c486 CFRunLoopRunSpecific + 470
    22  GraphicsServices                    0x0000000113d909f0 GSEventRunModal + 161
    23  UIKit                               0x0000000111696420 UIApplicationMain + 1282
    24  mobile-app                          0x000000010de2a55d main + 80
    25  libdyld.dylib                       0x0000000113fe4145 start + 1
    26  ???                                 0x0000000000000001 0x0 + 1
)

1 个答案:

答案 0 :(得分:0)

你的问题与tableview有关,在调用scrollToRowAtIndexPath之前重新加载你的tableView数据。