现将我所知道的storyboard 中的界面跳转方式进行简单总结:
跳转到新的页面
segue连线:在storyboard 中使用ctrl+鼠标拖动方式可以在两个页面间拖出一条segue连线
1,直接跳转:如果连线起点是一个按钮(或者其他可以点击的控件),则无需写代码就可以使点击按钮事件触发一次跳转。
2,利用segueID: storyboard segue 可以设置一个segueID, 代码中可以利用performSegueWithIdentifier 方法进行触发一个指定的segue跳转。
代码如下:
[self performSegueWithIdentifier:@"goView2" sender:sender];
storyBoardID 跳转:根据viewController 的storyboardID 可以获得viewController 的instance 并进行跳转
// 获取指定的Storyboard,name填写Storyboard的文件名
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 从Storyboard上按照identifier获取指定的界面(VC),identifier必须是唯一的
View3ViewController *view3 = [storyboard instantiateViewControllerWithIdentifier:@"view3"];
[self.navigationController pushViewController:view3 animated:YES];
此方法可用于跨storyboard的跳转。
返回
对于modal 类型的segue 可以在代码中利用
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);
返回,目前没有不写代码的方式能够返回。
- (IBAction)onClickBack:(id)sender {
[self dismissViewControllerAnimated:YES completion:Nil];
}
对于push 类型的segue, storyboard 会自动在navigationbar上生成back 按钮,但也可进行自定义。
此外,storyboard 可以与xib 混合使用,跳转到xib页面