Objective-C/Xcode - 以编程方式在视图控制器之间切换?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25179419/
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-09-15 05:21:17  来源:igfitidea点击:

Objective-C/Xcode - Switch between view controllers programatically?

iosobjective-cxcodeuiviewcontroller

提问by B-B.

How do you switch between view controllers programatically in an effective manner? I am currently utilising:

您如何以有效的方式以编程方式在视图控制器之间切换?我目前正在使用:

ViewController *viewController = [[ViewController alloc] init];
    [self presentViewController:viewController animated:YES completion:nil];

However this does not display the items that I've inserted using the interface builder. Only the items I've inserted programatically.

但是,这不会显示我使用界面构建器插入的项目。只有我以编程方式插入的项目。

I wish to do this, as I want to display a home button on each page.

我希望这样做,因为我想在每个页面上显示一个主页按钮。

回答by Retro

Give your viewController identity in StoryBord

在 StoryBord 中提供您的 viewController 身份

enter image description here

在此处输入图片说明

then into your code

然后进入你的代码

UIViewController *documetController       = [storyboard instantiateViewControllerWithIdentifier:@"MXDocumentViewController"];
[self.navigationController pushViewController:reviewListController animated:YES];