以编程方式从 Xib 执行 Segue [英] Perform Segue from Xib programmatically

查看:55
本文介绍了以编程方式从 Xib 执行 Segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多,但我还做不到.

I've search a lot but I can't do yet.

我的 .xib UI 带有一些按钮,与主故事板分开.

I've my .xib UI with some buttons, separated from main storyboard.

当我按下此按钮之一并显示另一个视图时,我需要执行一个操作.

I need to perform an action when I press one of this button and show another view.

如何直接从 IBAction 中的此类广告代码执行此操作?

How can I do this directly from code such ad inside an IBAction?

推荐答案

您无法执行从 XIB 到 Storybaord 的转场,
你需要的不是它
1) 获取 Storyboard 的实例.
2) 实例化 Storyboard 中的 ViewController(通过使用 Storyboard ID).
3) 将该 ViewController 推送到您的导航堆栈.

You can't perform segues from XIB to Storybaord,
Instead of it you need
1) Get Storyboard's instance.
2) Instantiate a ViewController that is inside the Storyboard (By using Storyboard ID).
3) Push that ViewController to to your navigation stack.

这是示例代码

UIViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"yourVcIdentifier"];
[self.navigationController pushViewController:vc animated:YES];

@"MainStoryboard" - 是 storybaord 的文件名(注意,它没有 .storyboard 扩展名)
@"yourVcIdentifier" - 是 ViewController 的 Storybaord ID.

要为某个 ViewController 提供 Storybaord ID,请打开 Storybaord,单击 ViewController 并指定Storyboard ID"字段.

To give a Storybaord ID to some ViewController, open the storybaord, click on the ViewController and specify the "Storyboard ID" field.

这篇关于以编程方式从 Xib 执行 Segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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