IOS——页面跳转
来源:互联网 发布:幕墙破解软件大全 编辑:程序博客网 时间:2024/05/18 03:22
一、直接推到下一个页面
定义好两个页面之后,在第一个界面添加一个button 并且对button实现changView方法
- -(IBAction)chang:(id)sender;
在 .m 文件里面实现
- -(void)chang:(id)sender{
- second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];
- [self presentViewController:secondview animated:YES completion:^{}];
- }
备注:second是第二个页面 这样就实现了第一种页面跳转,这种跳转的效果是从下面往上移动的效果
页面返回
当然,用这种方法来推到下一个页面,有时候还需要返回到上一个页面的时候,就需要额外实现一个方法 ,与 presentViewController: 对应的返回方法为dismissViewControllerAnimated: 在第二个页面添加一个button 对其添加一个方法,方法的实现里面加上这一行代码就可以了
- [self presentViewController:firstview animated:YES completion:^{}];
- [self dismissViewControllerAnimated:YES completion:^{}];
二、导航条跳转 UINavigationController
这个跳转方法需要的是借用UINavigationController来实现
UINavigationController相当于是一个容器,然后将所有的view都放到这个容器里面去
在代理.m 文件里面添加以下代码
就是添加一个导航条
- UINavigationController *_navTest = [[UINavigationController alloc] initWithRootViewController:_viewController];
导航条加进去之后第一个页面要加载哪一个? 用这一行代码来实现,并且是替换掉以前的那一个
- self.window.rootViewController = _navTest;
可以选择添加的代码:在 .m 加载的方法里面 添加这个页面的titile
- [self setTitle:@"first"];
实现的方法
- -(void)chang:(id)sender{
- second *secondview = [[second alloc] initWithNibName:@"second" bundle:nil];
- [self.navigationController pushViewController:secondview animated:YES];
- }
页面跳转之后,当然,自带的导航条上就有一个返回按钮,但是如果我们要自己代码实现这一个放回到上一个页面的话,我们用dismissViewControllerAnimated:是不能实现的,咋这里需要用的是popViewControllerAnimated 具体代码的实现为:
- [self.navigationController popViewControllerAnimated:YES];
这样就完成了 两种页面的跳转和返回了
0 0
- IOS——页面跳转
- IOS随笔——页面跳转
- IOS学习之——各种页面的跳转
- ios 页面跳转问题
- ios 页面跳转
- IOS之页面跳转
- iOS 页面跳转方式
- ios ViewController 页面跳转
- IOS 页面跳转
- ios页面跳转基础
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- ios ViewController 页面跳转
- IOS页面跳转方法
- iOS页面跳转
- [IOS]页面跳转 相关
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- IOS-UITextField
- shell的初始化文件:/etc/profile和/etc/bashrc(bash.bashrc)
- Linux进程关系
- UIWindow
- IOS——页面跳转
- cocos2d-x 网络编程二(cURL简单模拟登录的实现)
- 在Tomcat配置JNDI数据源的三种方式
- 推荐比赛的几次尝试
- CGI 编程学习
- Fragment里面的Viewpaper不显示内容不执行getItem的解决方案
- uva:Throwing cards away I
- Driver开发常见问题
- Android自定义View之一:初探实例