14

我有这个代码

 PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
 [self presentViewController:newView animated:YES completion:nil];

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

我试着把这段代码:

[self.navigationController pushViewController:newView animated:YES];

但不做任何事情。

谢谢

4

5 回答 5

41

目标-C:

PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"];
[self.navigationController pushViewController:newView animated:YES];

请注意以下几点,

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

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

迅速:

let newView = self.storyboard?.instantiateViewController(withIdentifier: "storyBoardIdentifier") as! PlaceViewController
self.navigationController?.pushViewController(newView, animated: true)
于 2014-05-28T08:59:57.217 回答
6

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

 [self performSegueWithIdentifier:@"identifier goes here" sender:self];
于 2012-12-21T09:01:08.870 回答
5

利用:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
[self presentViewController:newView animated:YES completion:nil];

或者:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"];
[self.navigationController pushViewController:newView animated:YES];
于 2017-07-07T14:17:07.757 回答
2

Swift 3.x

let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController
navigationController?.pushViewController(viewController, animated: true)
于 2017-02-24T15:44:22.160 回答
-1

默认情况下,Xcode 创建一个标准的视图控制器。我们首先将视图控制器更改为导航控制器。选择只需在菜单中选择“编辑器”,然后选择“嵌入”,然后选择“导航控制器” 第 1 步。选择主故事板 第 2 步。单击 Xcode 应用程序顶部的“编辑器”。第 3 步。点击“嵌入”

Xcode 自动将 View Controller 与 Navigation Controller 一起嵌入。

于 2016-03-08T08:53:38.870 回答