Switching storyboard view controller in Objective-

2019-08-10 02:45发布

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?

2条回答
Ridiculous、
2楼-- · 2019-08-10 03:18

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];
查看更多
Deceive 欺骗
3楼-- · 2019-08-10 03:37
  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.

查看更多
登录 后发表回答