4

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'

enter image description here enter image description here

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?

LampShade
  • 2,675
  • 5
  • 30
  • 60
  • Thank you for your update. Adding storyboardIdentifier manually to the storyboard file worked for me. I hope they will fix it soon. – anguish Mar 17 '15 at 12:36
  • I spoke with Xamarin Support, they say a bug fix is in the works and going through the QA process. The best options I've found are to downgrade your version of Xamarin (and maybe xcode?) or just do the workaround I've suggested here. But that workaround could lead to an ugly broken storyboard view for the future when they fix the bug... – LampShade Mar 17 '15 at 16:12
  • I'm just doing the Xamarin tutorial for multi-screen app and got this error. I thought I did something wrong ( I've used Visual Studio and the code is very similar). Looks like it is a bug. thx – Adam Mendoza Mar 29 '15 at 04:09
  • Manual editing fixed it. thx – Adam Mendoza Mar 29 '15 at 04:16

2 Answers2

1

For me the only solution seemed to open up xCode and add a storyboard there. Quite concerning that this bug reached the stable channel, which I'm working on...

Note: Manually editing the storyboard xml did not give me the correct runtime result...

Hutjepower
  • 1,241
  • 12
  • 17
  • Yeah the bug seems to be Xamarin specific, so doing it in xcode should work fine. Last I checked the bug fix was moving through the Alpha channel, it should be in Stable channel soon if not already. I haven't been updating lately. – LampShade Mar 30 '15 at 18:05
0

I get the same error. For some reason the old code works which uses the same approch. Only gets the problem when creating a new ViewController.