iOS版 - 从代码和故事板推的viewControlleriOS版 - 从代码和故事板推的view

2019-05-12 02:50发布

我有此代码

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

我可以改变看法,但我将推动这一观点时,我在此页面返回的状态持续。

我尝试把这个代码:

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

但没有做任何事情。

谢谢

Answer 1:

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

检查两件事情,

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

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



Answer 2:

对于故事板,你应该使用performSegueWithIdentifier像这样:

 [self performSegueWithIdentifier:@"identifier goes here" sender:self];


Answer 3:

使用:

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];


Answer 4:

斯威夫特3.X

let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController
navigationController?.pushViewController(viewController, animated: true)


Answer 5:

默认情况下,Xcode创建标准视图控制器。 我们首先改变视图控制器导航控制器。 选择只需在菜单中选择“编辑”,然后选择您的Xcode应用程序的顶部“嵌入”,其次是“导航控制器”第1步:选择主故事板步骤2.Click上的“编辑”。 步骤3.点击“嵌入”

Xcode中自动嵌入与导航控制器的视图控制器。



文章来源: iOS - Push viewController from code and storyboard