本文介绍了以编程方式创建转场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用的 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.

这篇关于以编程方式创建转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:48