iOS - 从代码和故事板推送viewController

Xos*_*ose 11 storyboard uiview pushviewcontroller ios xcode4.5

我有这个代码

 PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
 [self presentViewController:newView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我可以更改视图,但是当我在此页面返回时,我会推动此视图,状态仍然存在.

我试着把这段代码:

[self.navigationController pushViewController:newView animated:YES];
Run Code Online (Sandbox Code Playgroud)

但什么也没做.

谢谢

Vin*_* TP 39

PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"];
[self.navigationController pushViewController:newView animated:YES];
Run Code Online (Sandbox Code Playgroud)

检查2件事,

  1. 你的故事板标识符是正确的.

  2. 根视图有导航控制器.


Sum*_*nth 5

对于情节提要,应该这样使用performSegueWithIdentifier

 [self performSegueWithIdentifier:@"identifier goes here" sender:self];
Run Code Online (Sandbox Code Playgroud)

  • 我建议您阅读http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1本教程 (2认同)

小智 5

使用:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
[self presentViewController:newView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

要么:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
[self.navigationController pushViewController:newView animated:YES];
Run Code Online (Sandbox Code Playgroud)