Lobbe Lobbe - 1 month ago 15
iOS Question

Need to go back to main view

Can you help me, I got a navigationbar, with a back button, when I press the back button I want to go back to my view, but not sure it's the correct way, I'm doing it.

public void Login()
{
cmdLogin.TouchUpInside += delegate {

var rootViewController = new UINavigationController();
LoginViewController LVC = new LoginViewController();
rootViewController.PushViewController(LVC, false);

this._window.RootViewController = rootViewController;
this._window.MakeKeyAndVisible();
_backButton = new UIBarButtonItem("Back", UIBarButtonItemStyle.Bordered, onBackSelected);

LVC.NavigationItem.LeftBarButtonItem = _backButton;
LVC.Title = "Login";

};

}


and my onBackSelected looks like this.

private void onBackSelected(object o, EventArgs e)
{
_window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new CirkelWithButtonsViewController (_window);
_window.RootViewController = viewController;
_window.MakeKeyAndVisible ();
}


I don't know if this is the correct way to go back? please provide a better solution :)

Answer
NavigationController.PopToViewController (yourViewController, true);

is the translation of @jitendra-deore answer to xamarin.iOS C#