Switching storyboard view controller in Objective-C

瘦欲@ 提交于 2019-12-24 11:19:32

问题


I am trying to switch to different ViewController on same storyboard like so:

CalendarViewController *CalViewController = [[CalendarViewController alloc] init]; [self presentViewController:CalViewController animated:NO completion:nil];

When I run this action, corresponding implementation file executes NSLog message but screen goes black with no errors being displayed.

How do I fix this?


回答1:


Let's suppose you created your CalendarViewController interface in a storyboard, and you assigned it the identifier "ControllerIdentifier".

If you want to load it from inside another View Controller, you can instantiate your CalendarViewController and present it like this:

CalendarViewController *calViewController = (CalendarViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ControllerIdentifier"]
[self presentViewController:calViewController animated:NO completion:nil];



回答2:


  1. You can use Segue to push calViewController.

  2. You can use the code below;

    CalendarViewController *CalViewController = (CalendarViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"CalendarViewControllerIdentifier"]; [self presentViewController:CalViewController animated:NO completion:nil];

But if you choose the second option, you have to set CalendarViewController's Storyboard Identifier to CalendarViewControllerIdentifier from your storyboard.



来源:https://stackoverflow.com/questions/28077933/switching-storyboard-view-controller-in-objective-c

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