[英]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: 这是情节提要的图像:
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
。
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.