简体   繁体   English

情节提要视图控制器未实例化?

[英]Storyboard View Controller not instantiated?

I am trying to instantiate a new view controller in my storyboard with this code but it does nothing and stays on the old storyboard. 我试图使用此代码在我的情节提要中实例化一个新的视图控制器,但它不执行任何操作并保留在旧的情节提要上。

Here is the code: 这是代码:

(void)menuSelect:(id)sender {
UIButton *button = (UIButton*) sender;
switch (button.tag) {
    case 0: {
        HomeViewController *hc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Home"];
        [self presentViewController:hc animated:YES completion:nil];

        break;
    }

The storyboard file name is Main.Storyboard and the id for the viewController is Profile. 故事板的文件名为Main.Storyboard,而viewController的ID为Profile。

Here is the image of what the storyboard looks like: 这是情节提要的图像:

在此处输入图片说明

Issue 问题

You are passing "home" as an indentifier of HomeViewController , while it is "profile". 您正在传递“ home”作为HomeViewController ,而它是“ profile”。 So what you are telling to program is: Get the storyboard with the name "main", instantiate the HomeViewController with identifier "home". 因此,您要告诉程序的是:获得名为“ main”的storyboard HomeViewController ,实例化具有标识符“ home”的HomeViewController

Solution

Change the code to: 将代码更改为:

HomeViewController *hc=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Profile"];
[self presentViewController:hc animated:YES completion:nil];

Instantiating the storyboard does not cause any View Controller to be displayed. 实例化情节提要板不会导致显示任何View Controller。 You have to call presentViewController from another view controller. 您必须从另一个视图控制器调用presentViewController。

暂无
暂无

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

相关问题 MVYMenuViewController:如何销毁从情节提要中实例化的视图控制器 - MVYMenuViewController: How to destroy a view controller which was instantiated from storyboard 使用情节提要实例化的控制器的解除分配 - Deallocation of controller instantiated using storyboard 弹出情节提要实例化的视图控制器,然后将其重新推送到导航控制器堆栈后,如何存储数据 - How to store data after popping a storyboard instantiated view controller to then repush it to the navigation controller stack 如何在情节提要中自定义由标识符实例化并推送到导航堆栈的视图控制器的UINavigationItem? - How to custom in storyboard my view controller's UINavigationItem that is instantiated by identifier and pushed onto navigation stack? 如何从情节提要中实例化UIButton类中的视图控制器实例 - How to get instance of view controller in UIButton class which is instantiated from storyboard 如何在从界面构建器中的Storyboard场景实例化的视图控制器上调用自定义init? - How do I call a custom init on a view controller instantiated from a Storyboard scene in interface builder? Swift Xcode错误:线程1信号SIGABRT“从情节提要中实例化了视图控制器,但未获得UITableView - Swift xcode error: Thread 1 signal SIGABRT "instantiated view controller from storyboard but didn't get a UITableView 运行时错误消息:loadView 实例化视图 controller,标识符 ViewController 来自 storyboard Main,但没有获得 TableView - Runtime Error message: loadView instantiated view controller with identifier ViewController from storyboard Main,but didn't get a TableView '实例化视图 controller 与标识符“”来自 storyboard“主”,但在尝试以模式方式呈现视图 controller 时没有获得 UITableView - 'instantiated view controller with identifier “” from storyboard “Main”, but didn't get a UITableView' while trying to present view controller modally 从情节提要上的Xib实例化视图进行无限循环 - Infinite loop on instantiated view from xib on storyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM