keyboard
keyboard

Reputation: 2355

iOS - Pushing the same view controller instance more than once is not supported

First of all, yes I know that this is a common problem and has been discussed multiple times. Though I can't solve mine and I'd like to show you my stacktrace to see if any of you have an idea what the reason of this crash is in my case.

I did search for any call for pushViewController in the whole app and before pushing the viewController I check if its already there:

    if (![navigationController.viewControllers containsObject: channelViewController])
    {
        [navigationController pushViewController: channelViewController animated:NO];
    }

This reduced the amount of crashes for my users, though the crash still happens.

Here's the stacktrace:

Fatal Exception: NSInvalidArgumentException
Pushing the same view controller instance more than once is not supported (<ChannelViewController: 0x1b827360>)

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2280010b __exceptionPreprocess
1  libobjc.A.dylib                0x21fa6e17 objc_exception_throw
2  UIKit                          0x269d17e9 -[UINavigationController loadView]
3  UIKit                          0x26cc2271 __54-[UINavigationController pushViewController:animated:]_block_invoke
4  UIKit                          0x269d0e79 -[UINavigationController pushViewController:animated:]
5  UIKit                          0x26a3e979 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
6  UIKit                          0x26a6a31d -[_UIViewControllerTransitionContext _runAlongsideCompletions]
7  UIKit                          0x26a690b1 -[_UIViewControllerTransitionContext completeTransition:]
8  UIKit                          0x26a68ed9 -[UITransitionView notifyDidCompleteTransition:]
9  UIKit                          0x26a68a4d -[UITransitionView _didCompleteTransition:]
10 UIKit                          0x26a685ef -[UITransitionView _transitionDidStop:finished:]
11 UIKit                          0x26977605 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
12 UIKit                          0x269774ff -[UIViewAnimationState animationDidStop:finished:]
13 QuartzCore                     0x24a3ea21 CA::Layer::run_animation_callbacks(void*)
14 libdispatch.dylib              0x22379b47 _dispatch_client_callout
15 libdispatch.dylib              0x22387ee1 _dispatch_main_queue_callback_4CF$VARIANT$mp
16 CoreFoundation                 0x227c33fd __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
17 CoreFoundation                 0x227c18f7 __CFRunLoopRun
18 CoreFoundation                 0x22714bf9 CFRunLoopRunSpecific
19 CoreFoundation                 0x227149e5 CFRunLoopRunInMode
20 GraphicsServices               0x23960ac9 GSEventRunModal
21 UIKit                          0x269a4ba1 UIApplicationMain

Upvotes: 3

Views: 5424

Answers (1)

Divyesh
Divyesh

Reputation: 2393

if (![navigationController.topviewcontroller containsObject: channelViewController])
{
    [navigationController pushViewController: channelViewController.animated:NO];
}

try this, it will work! The error you are getting is just because channelViewController is already in the navigation stack. And still if you want to push it just do this:

var topview = navigationController.topviewcontroller;
topview.RemoveFromParentViewController();
[navigationController pushViewController: channelViewController animated:NO];

Upvotes: 1

Related Questions