问题描述
我有 2 个故事板:Activities.storyboard
和 Contacts.storyboard
.
I have 2 storyboards: Activities.storyboard
and Contacts.storyboard
.
在 Contacts.storyboard
上,我有一个 ViewController:ContactDetails
.
On Contacts.storyboard
I have a ViewController: ContactDetails
.
在 Activities.storyboard
我需要参考 Contacts.storyboard
我在 Activities.storyboard
上创建了一个 Storyboard Reference
并引用了 ContactDetails
.
I created a Storyboard Reference
on Activities.storyboard
and referenced the ContactDetails
.
我尝试以编程方式加载这个视图控制器
And I tried load this View Controller programmatically
var viewController = Storyboard.InstantiateViewController(nameof(ContactDetails));
NavigationController.PushViewController(viewController, true);
但我没有工作以编程方式加载为普通的视图控制器
But I didn't work to load programmatically as a normal View Controller
Foundation.MonoTouchException:抛出的 Objective-C 异常.姓名:NSInvalidArgumentException 原因:Storyboard() 不包含带有标识符的视图控制器'联系方式'
我知道它是这样工作的:
I know it works this way:
var storyboard = UIStoryboard.FromName(nameof(Contact), null);
var viewController = storyboard.InstantiateViewController(nameof(ContactDetails));
NavigationController.PushViewController(viewController, true);
但是我想使用参考视图控制器,可以吗?
推荐答案
显然加载 Storyboard Reference 的唯一方法是使用 Segue.
Apparently the only way to load Storyboard Reference is with Segue.
以编程方式唯一的方法是实例化Storyboard
,然后实例化ViewController
Programmatically the only way is instantiate the Storyboard
and after instantiate the ViewController
像这样:
var storyboard = UIStoryboard.FromName(nameof(Contact), null);
var viewController = storyboard.InstantiateViewController(nameof(ContactDetails));
NavigationController.PushViewController(viewController, true);
这篇关于Xamarin iOS - 以编程方式加载故事板参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!