0
votes

I am creating xamarin.IOS app in visual studio where i want to navigate to different view controllers depending upon the situation. so, i added code for navigation as,

var controller = this.Storyboard.InstantiateViewController("New") as UIViewController;
NavigationController.PushViewController(controller, true);

I have added a view controller in storyboard with Both Storyboard id and restoration is set to New. (Even selected use storyboard id checkbox).

But, I keep on getting the error

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Storyboard () doesn't contain a view controller with identifier 'New'.

How to navigate to a new view controller.???

1

1 Answers

0
votes

In order to navigate to a new ViewController, you need a designer file (I use a .xib file), Wether there's controls on it or not. You need to give this a name that's similar to the name of your ViewController (so it's easier to remember).

When creating a new ViewController, you should use the PushViewController method and in this method's parameters, you should put the ViewController you wish to create (push).

So, for example:

public void NewWindow ()
{
    this.NavigationController.PushViewController (new NewViewController(), true);
}

Then, in this NewViewController, at its constructor, you need to refer the constructor to the .xib file, so it knows where it can draw controls on.

Example:

public partial class NewViewController : UIViewController
{
    public NewViewController () : base ("NewViewController", null)
    {
    }
}

After that's done, you can follow your regular programming.

I hope this helps. Good luck!

Love and regards, Björn