Forum Xamarin.iOS

correct usage of storyboard in iOS Designer

wosiwosi Member ✭✭

I'm starting with iOS-Apps and I have a problem linking storyboard <=> view controller. I've been experimenting a lot with creating iOS Single View Apps and I realised that everything works fine if one goes with the default settings: creating the app in VS for mac I get a Main.storyboard and a ViewController.cs already hooked up. The controls I've added to the design surface get registered in the designer.cs. Running the app produces no error.

However things are different when I don't go with the defaults: deleting the default Main.storyboard and ViewController.cs and replacing them with a separate Storyboard / View Controller file always leads to the following exception:

NSInvalidArgumentException Reason: Could not find a storyboard named ‘Main’ in bundle NSBundle

I've tried a lot of solutions: removing the entry from Info.plist => Deployment Info => Main Interface, deleting the entries in Info.plist with "Main", setting
Info.plist => Deployment Info => Main Interface to the storyboard I've created myself. All this doesn't work and produces the mentioned exception. So I'd like to know whether it is at all possible to set up your own storyboard / view controller combination via the iOS Designer interface or is this only possible only if one goes with the defaults (Main.storyboard, ViewController.cs) or isn't it possible at all to do via the iOS Designer but instead has to be done via code.

Also how would one have to go about, if one wanted to use XIB instead of the storyboard?

My setting is as follows: VS for Mac Community 8.3.10 and Xcode 11.2.1. Any answers or links showing the right direction are very much appreciated.

Best Answer


  • wosiwosi Member ✭✭

    @JGoldberger :smile: Thanks for your elaborate description - that really helped me. I only had to modify your solution a little bit to get it working. I had to create the ViewController class (your step 16) BEFORE dragging the View Controller onto the canvas (your step 13). Doing it this way ensured that the controls added to the View Controller were also registered in the designer file. When I proceeded the way you suggested the class for the View Controller would be generated - however the designer file then just contained an empty class - without any controls being registered in the designer that had been added to the View of the View Controller. But other than that it worked out wonderfully.

  • wosiwosi Member ✭✭

    @JGoldberger : there is one more addition I needed to add to your solution (which I only discovered now). After making the mentioned changes all of a suddon I've got an "Failed to marshal the Objective-C object" exception. After adding another constructor to the View Controller class like:

    public MyViewController(IntPtr p) : base(p) {}

    that exception was canceled out and it worked again. Looks like the next bump in the road is soon to arrive ;)

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    Glad you got it working.

    In my sample, I did not have any controls added to the view controller. It sounds like you were trying to add a storyboard and view controller that already had stuff added to them, so that explains that difference.

    Also in my example, that constructor is automatically added to the new view controller. This was probably not in your existing view controller class that you added.

Sign In or Register to comment.