I have a Xamarin.iOS solution that has 2 projects. First one is the main iOS app project, the second one is an Xamarin.iOS library project. I have a storyboard in each project, in iOS project the storyboard is simple with a single view controller, its job is to initialize view controller and load the storyboard from the library project.
The reason behind this is we want to create a copy of our app branded for a specific client. So the main app logic will be in the library project and the main iOS app contains all the styling for the client branded app.
I have done this with mild success. I am able to load the second storyboard by calling this in the ViewDidAppear
method of the first storyboard.
var sb = UIStoryboard.FromName("Storyboard", null);
var ctlr = sb.InstantiateInitialViewController();
this.PresentViewController(ctlr, true, null);
The problem comes when I try to add an outlet for anything in the UIViewController
of the second storyboard. I got the following error:
Objective-C exception thrown. Name: NSUnknownKeyException Reason:
[<UIViewController 0x166d5120> setValue:forUndefinedKey:]: this class
is not key value coding-compliant for the key SecondText.
SecondText
is the name of the outlet to the UITextField
on the second storyboard.
This might not be the best way to achieve what I want, but I am still puzzled why this method doesn't work when an outlet is added to the view controller.
This problem doesn't happen when the second storyboard is on the main iOS app project.
Would be grateful if anyone could shed any light on this. I have uploaded my test project here if you want to have a look.
https://github.com/kckc/testShareStoryboard
A final note is that I noticed the ViewDidLoad
method didn't fire on the view controller of the second storyboard when it's in the library project, may be this could be the cause of it?
Instead of using:
var ctlr = sb.InstantiateInitialViewController();
try instantiating the second viewcontroller by name:
UIStoryboard sb = UIStoryboard.FromName("Storyboard", null);
nameofsecondviewcontroller ctlr = sb.InstantiateViewController("nameofsecondviewcontroller") as nameofsecondviewcontroller;
PresentViewController(ctlr, true, null);
This should use the designer of the second viewcontroller to initialise the controls of the View.