Forum Xamarin.iOS

PushViewController issue

iKaniKan USMember

I am trying to display a new view controller when a certain action is done in my application. I do this using the code below. I notice that the view controller loads but method ViewDidDisappear gets called almost immediately afterwards. I'm not sure why this is happening, any advice?

                var window = new UIWindow (UIScreen.MainScreen.Bounds); 
                var rootNavigationController = new UINavigationController(); 

                GroupListViewController groupListViewController = new GroupListViewController(); 
                rootNavigationController.PushViewController(groupListViewController, false); 

                window.RootViewController = rootNavigationController; 
                window.MakeKeyAndVisible (); 


  • iKaniKan USMember

    Apologies for the multiple threads, the site gave me a "Service not available" error when trying to post but it seems like it still went through.

  • GuillermoGutierrezGuillermoGutierrez ESMember ✭✭✭

    You are creating a completely new View hierarchy just for pushing a new UIViewController. You don't need to create a new UIWindow or even a new UINavigationController. It looks like a copy-paste of the AppDelegate code.

    Probably what you want to achieve could be reduced to:

    GroupListViewController groupListViewController = new GroupListViewController(); 
    NavigationController.PushViewController(groupListViewController, false);

    All UIViewController have access to their navigation controller by the NavigationController property. Just make sure that the current view controller is inside a UINavigationController.

Sign In or Register to comment.