Creating a segue programmatically(以编程方式创建 segue)
问题描述
我有一个通用的 UIViewController
,我的所有 UIViewsControllers
都扩展它以重用一些通用操作.
I have a common UIViewController
that all my UIViewsControllers
extend to reuse some common operations.
我想在这个通用"UIViewController
上设置一个 segue,以便所有其他 UIViewControllers
继承.
I want to set up a segue on this "Common" UIViewController
so that all the other UIViewControllers
inherit.
我试图弄清楚如何以编程方式做到这一点.
I am trying to figure out how do I do that programmatically.
我想问题也可能是如何为我的所有 UIViewControllers
设置 segue
而无需进入故事板并手动完成.
I guess that the question could also be how do I set a segue
for all my UIViewControllers
without going into the story board and do them by hand.
推荐答案
根据定义,segue 不能真正独立于故事板而存在.它甚至出现在类的名称中:UIStoryboardSegue
.您不会以编程方式创建 segue - 它是故事板运行时为您创建它们.您通常可以在视图控制器的代码中调用 performSegueWithIdentifier:
,但这依赖于已经在情节提要中设置了 segue 以供参考.
By definition a segue can't really exist independently of a storyboard. It's even there in the name of the class: UIStoryboardSegue
. You don't create segues programmatically - it is the storyboard runtime that creates them for you. You can normally call performSegueWithIdentifier:
in your view controller's code, but this relies on having a segue already set up in the storyboard to reference.
我认为您要问的是如何在通用视图控制器(基类)中创建一个方法,该方法将转换为新的视图控制器,并由所有派生类继承.你可以通过为你的基类视图控制器创建一个像这样的方法来做到这一点:
What I think you are asking though is how you can create a method in your common view controller (base class) that will transition to a new view controller, and will be inherited by all derived classes. You could do this by creating a method like this one to your base class view controller:
- (IBAction)pushMyNewViewController
{
MyNewViewController *myNewVC = [[MyNewViewController alloc] init];
// do any setup you need for myNewVC
[self presentModalViewController:myNewVC animated:YES];
}
然后在您的派生类中,在单击相应按钮或选择表格行或其他任何情况时调用该方法.
and then in your derived class, call that method when the appropriate button is clicked or table row is selected or whatever.
这篇关于以编程方式创建 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式创建 segue
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01