繁体   English   中英

在没有情节提要的情况下更改视图控制器

[英]Changing view controllers without the storyboard

我正在尝试更改视图,但出于根本无关紧要的原因,我想通过代码而不是情节提要来完成此操作,并找到了以下代码:

[[self ] presentModalViewController:[self destinationViewController] animated:NO];

问题是我不知道要为presentModalViewController或destinationViewController放入什么。 有什么方法可以弄清楚我的观点叫什么,以便我可以提出他们的意见?

在顶部,你应该有

#import "NameOfViewController.h"

然后再

UIViewController *destinationViewController = [[NameOfViewController alloc] init];
[self presentViewController:destinationViewController animated:NO completion:nil];

由于不建议使用后者,因此请使用presentViewController而不是presentModalViewController 希望对您有用。

在您给出的示例中, [self destinationViewController]创建并返回一个UIVIewController。

您可以:

  1. 从NIB文件加载一个

    controller = [[MyController alloc] initWithNibName:@"nib-resource-name" bundle:nil];

  2. 从情节提要中加载一个

    MyController * controller = [self.storyboard instantiateViewControllerWithIdentifier:@"controller-storyboard-id"];

  3. 以编程方式创建一个

    如何以编程方式创建UIViewController?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM