iOS 关于页面跳转和传值
iOS 页面间的跳转目前有3种方式:
1、利用StroyBorad
这里以TableView的静态cell为例,选中第一个cell按住ctrl往新的ViewController上拖,弹出对话框选择show或present modally
2、代码跳转
- (IBAction)Push:(id)sender {
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType: kCATransitionMoveIn];
[animation setSubtype: kCATransitionFromTop];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PresentViewController * info = [mainStoryboard instantiateViewControllerWithIdentifier:@"PresentViewController"];
[self.navigationController pushViewController:info animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:@"1"];
}
这是navigationController的push 有默认的返回
- (IBAction)presentView:(id)sender {
UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PresentViewController * info = [mainStoryboard instantiateViewControllerWithIdentifier:@"PresentViewController"];
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:info animated:YES completion:^{
}];
}
这是弹出模态框。调用
[self dismissViewControllerAnimated:YES completion:^{
}];返回上个界面
3、Seque跳转
这个方式要设定Seque的identifier进行动态绑定加载。选定源控制器的Controller
按住ctrl拖到要显示的Controller上,在弹出框上选择弹出类型。修改这个Seque的identifier=PushCtrl
修改代码:
[self performSegueWithIdentifier:@"PushCtrl" sender:self]; 这样就会跳转到这个identifier指定的页面上。
关于show,present modally可以参考官方文档 https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/chapters/StoryboardSegue.html
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。