在最近的Xamarin iOS或Xamarin Studio更新中,出现了一些变化,我现在只需简单地使用PresentViewController就会遇到奇怪的错误。这完全相同的代码一个月前是可以工作的。我认为Xamarin中有些东西发生了改变,因为他们最近在Storyboard Properties/Widget中添加了"Module"行。
以下代码生成了基于下面Storyboard截图的错误:
Foundation.MonoTouchException: Objective-C 异常抛出。名称:NSInvalidArgumentException 原因:Storyboard()不包含标识为“CustomViewController”的视图控制器
我的Xamarin Studios版本是5.8 build 443,Xamarin iOS 是8.8.0.2,Xcode是6.2(6776)。
---------------更新----------------
所以我在文本编辑器中打开了Storyboard文件,并检查了Xamarin Designer生成的代码。几个月前创建的Controller具有storyboardIdentifier,但今天创建的Controller没有storyboardIdentifier,尽管我在Xamarin Designer中明确设置了它... 这听起来很麻烦。以下是代码:
旧的控制器是几个月前更新之前生成的:
今天生成的新代码导致了异常:
// Instantiate and push controller
UIStoryboard storyBoard = UIStoryboard.FromName("MainStoryboard", null);
CustomViewController navigationController = storyBoard.InstantiateViewController("CustomViewController") as CustomViewController;
this.InvokeOnMainThread(() => {
this.PresentViewController(
navigationController,
true,
null
);
});
以下代码生成了基于下面Storyboard截图的错误:
Foundation.MonoTouchException: Objective-C 异常抛出。名称:NSInvalidArgumentException 原因:Storyboard()不包含标识为“CustomViewController”的视图控制器
我的Xamarin Studios版本是5.8 build 443,Xamarin iOS 是8.8.0.2,Xcode是6.2(6776)。
---------------更新----------------
所以我在文本编辑器中打开了Storyboard文件,并检查了Xamarin Designer生成的代码。几个月前创建的Controller具有storyboardIdentifier,但今天创建的Controller没有storyboardIdentifier,尽管我在Xamarin Designer中明确设置了它... 这听起来很麻烦。以下是代码:
旧的控制器是几个月前更新之前生成的:
<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>
今天生成的新代码导致了异常:
<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>
如果您手动在文本编辑器中打开故事板文件并添加storyboardIdentifier,那么故事板就可以成功打开而不会出现异常。看起来像是一个bug?