Xamarin iOS - 以编程方式加载故事板参考 [英] Xamarin iOS - Load Storyboard Reference Programatically

查看:33
本文介绍了Xamarin iOS - 以编程方式加载故事板参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个故事板:Activities.storyboardContacts.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() 不包含带有标识符的视图控制器'联系方式'

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Storyboard () doesn't contain a view controller with identifier 'ContactDetails'

我知道它是这样工作的:

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 - 以编程方式加载故事板参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆