iOS – 从代码和故事板推送viewController
我有这个代码
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceView"]; [self presentViewController:newView animated:YES completion:nil];
而且我可以改变看法,但是当我在这个页面返回的时候,我会推动这个观点,这个状态依然存在。
我试着把这个代码:
[self.navigationController pushViewController:newView animated:YES];
但没有做任何事情。
谢谢
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"]; [self.navigationController pushViewController:newView animated:YES];
检查2件事情,
-
你的故事板标识符是正确的。
-
根视图有导航控制器。
对于故事板,你应该像这样使用performSegueWithIdentifier
:
[self performSegueWithIdentifier:@"identifier goes here" sender:self];
Swift 3.x
let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController navigationController?.pushViewController(viewController, animated: true)
默认情况下,Xcode创build一个标准的视图控制器。 我们首先将视图控制器更改为导航控制器。 select菜单中的简单select“编辑器”,然后select“embedded”,然后select“导航控制器”。第1步。select主要故事板第2步。单击Xcode应用程序顶部的“编辑器”。 第3步。点击“embedded”
Xcode自动embedded视图控制器与导航控制器。
使用:
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];
- 坚持UITableView标题视图顶部时,故事板中创build标题
- 将某些XIB / Storyboardstring标记为不可本地化
- 当使用loadNibNamed时,为什么我们必须使用'first'? 我们不想将我们的源代码的不同实体分开吗?
- 如何设置故事板的代表
- 自动布局不断拉伸UIImageView
- 在故事板的XCode 4中以模态方式推送视图时出现“不平衡调用开始/结束外观转换”警告
- 如何在didReceiveMemoryWarning中使用storyboard卸载视图并重新创build视图
- 延迟使用instantiateViewControllerWithIdentifier但不执行SegueWithIdentifier?
- Xcode 6 Storyboard不能居中