ios 以编程方式打开视图控制器而不使用 Seque

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15686233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:55:11  来源:igfitidea点击:

Open View Controller programmatically and not using a Seque

iosobjective-cios6

提问by RGriffiths

I know that this is a really simple question but I am getting nowhere.

我知道这是一个非常简单的问题,但我一无所获。

I have a storyboard and all the view controllers are opened using segues which is fine, but I would like to open one of them using code when the button is pressed.

我有一个故事板,所有的视图控制器都是使用 segues 打开的,这很好,但我想在按下按钮时使用代码打开其中一个。

What is the line for opening the view controller called ViewControllerMonitorMenuwhen the testSlidersbutton is pressed:

按下按钮ViewControllerMonitorMenu时调用的打开视图控制器的行是什么testSliders

- (IBAction)testSliders:(id)sender
{

}

回答by RGriffiths

I have finally got it. Thanks for everyone's help:

我终于明白了。感谢大家的帮助:

ViewControllerMonitorMenu *monitorMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerMonitorMenu"];
[self presentViewController:monitorMenuViewController animated:NO completion:nil];

回答by iPatel

This code programatically created objectof ViewControllerMonitorMenuand also you can go on it.

这段代码以编程方式创建的对象ViewControllerMonitorMenu你也可以继续下去。

- (IBAction)testSliders:(id)sender 
    {
       ViewControllerMonitorMenu * object = [[ViewControllerMonitorMenu alloc] init];
        [self presentViewController:object animated:YES completion:nil];

    }