这两天被IOS的ViewController搞得很烦。首先代码实现跳转的方法。在当前ViewController对象V1
SecondViewController *VC = [[SecondViewController alloc]init];
//VC= nav;
//显示新视图控制器
//VC 新视图控制器对象
//parameter 2 是否有动画效果。
//parameter 3 切换结束后功能调用
[V1 presentViewController:VC animated:YES completion:nil];
但是这样跳过去的是代码创建的ViewController。
并不会关联到在storyboard的中的SecondViewController类
要是要关联Storyboard 里面的ViewController。
首先获取storyboard 对象
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
一般在infoplist可以找到 storyboard 名字“Main”
SecondViewController *VC = [storyboard instantiateViewControllerWithIdentifier:@"MyView"];
[V1 presentViewController:VC animated:YES completion:nil];
然后要给storyboard中的SecondViewController一个ID MyView。最后要把创建时候的ViewdidLoad方法删除。否则会有冲突。