How to load view controller without button in storyboard?

大兔子大兔子 提交于 2019-12-24 01:47:06

问题


I want to load view controller without button. I set the identifier to 10 and tried to use

if(...){ 
    //load ViewController2
    [[self storyboard] instantiateViewControllerWithIdentifier:@"10"];
}

but nothing happens.

with this function its doesnt work too

 UIViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier:@"10"];

[self.navigationController pushViewController:vc];

here is my progect http://www.sendspace.com/file/kfjhd5

whats a problem?


回答1:


Calling instantiateViewControllerWithIdentifier: will instantiate a view controller, as it says. Nothing more. If you want to actually show it you have to use a variable and push it to your view controller stack.

UIViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier:@"10"];
[self.navigationController pushViewController:vc];

Of course you have to be using a UINavigationController to do this.



来源:https://stackoverflow.com/questions/12480929/how-to-load-view-controller-without-button-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!