Something changed in a recent Xamarin iOS or Xamarin Studio update and I'm now getting strange errors with simply PresentViewController. This same exact code worked a month ago. I think something in Xamarin changed because they just recently added the "Module" line in the storyboard Properties/Widget
// Instantiate and push controller
UIStoryboard storyBoard = UIStoryboard.FromName("MainStoryboard", null);
CustomViewController navigationController = storyBoard.InstantiateViewController("CustomViewController") as CustomViewController;
this.InvokeOnMainThread(() => {
this.PresentViewController(
navigationController,
true,
null
);
});
The above code generates this error based on the storyboard screenshot below:
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Storyboard () doesn't contain a view controller with identifier 'CustomViewController'
My Xamarin Studios version is 5.8 build 443 and Xamarin iOS is 8.8.0.2 and Xcode is 6.2 (6776)
---------------Update----------------
So I'm opening the storyboard file in a text editor and examining the code generated by Xamarin Designer. The Controller created months ago has a storyboardIdentifier but the Controller created today does not have a storyboardIdentifier even though I've clearly set it in Xamarin Designer.... That sounds problematic. Here's the code:
Old Controller generated Months ago before the update:
<navigationController definesPresentationContext="YES" id="123" sceneMemberID="viewController" storyboardIdentifier="RedViewNavigationController" restorationIdentifier="RedViewNavigationController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="126">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</navigationBar>
<connections>
<segue destination="125" kind="relationship" relationship="rootViewController" id="124"/>
</connections>
</navigationController>
New Code generated today that leads to the exception:
<navigationController definesPresentationContext="YES" id="164" sceneMemberID="viewController" restorationIdentifier="JZCustom">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="167">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</navigationBar>
<connections>
<segue destination="166" kind="relationship" relationship="rootViewController" id="165"/>
</connections>
</navigationController>
So once you manually open the storyboard file in a text editor and add the storyboardIdentifier, the storyboard opens successfully without an exception. Looks like a bug?