iOS开发从入门到精通--UIViewController使用
2016-07-17 18:20
417 查看
UIViewController使用:从ViewController.m跳转到ViewController02.m,ViewController.m的生命周期问题,ViewController02消失之后再显示ViewController的过程
ViewController.m里面的代码:
创建一个ViewController02,在ViewController02.m里代码如下:
ViewController.m里面的代码:
#import "ViewController.h" #import "ViewController02.h" @interface ViewController () @end @implementation ViewController //当屏幕被点击时,调用此函数 - (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //创建视图控制器2 ViewController02 *vc =[[ViewController02 alloc]init]; //显示一个新的视图控制器到屏幕上 //p1:新的视图控制器对象 //p2:使用动画切换动画效果 //p3:切换结束后功能调用,不需要直接传nil [self presentViewController:vc animated:YES completion:nil]; } //第一次程序加载视图时调用 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor=[UIColor blueColor]; NSLog(@"viewDidLoad 第一次加载视图"); } //当视图控制器的视图即将显示时,调用此函数 //视图分为:1显示前(不显示)2正在处于显示状态 3已经被隐藏 //参数:表示是否用动画切换后显示 //每一次视图显示时都会被调用 - (void) viewWillAppear:(BOOL)animated{ NSLog(@"viewWillAppear 视图即将显示"); } //视图即将消失时,调用此函数 //参数:表示是否调用动画切换后消失 //当前状态:视图还是显示在屏幕上的 - (void) viewWillDisappear:(BOOL)animated{ NSLog(@"viewDidDisappear 视图即将消失"); } //当视图已经显示到屏幕后的瞬间调用此函数 //参数:表示是否调用动画切换显示 //当前状态:已经显示到屏幕上 - (void) viewDidAppear:(BOOL)animated{ NSLog(@"viewDidAppear 视图已经显示"); } //当前视图已经消失从屏幕上 //参数:表示是否调用动画 //当前状态:当前视图控制视图已经消失从屏幕上 - (void) viewDidDisappear:(BOOL)animated{ NSLog(@"viewDidDisappear 视图已经消失"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
创建一个ViewController02,在ViewController02.m里代码如下:
#import "ViewController02.h" @interface ViewController02 () @end @implementation ViewController02 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //控制器2的颜色为红色 self.view.backgroundColor=[UIColor redColor]; } //点击当前控制器2的界面屏幕时 - (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //使当前的控制器消失掉 //p1:是否有动画效果 //p2:结束后是否调用功能block块操作 [self dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- DRUID连接池的实用 配置详解
- 超级精简版/超精简/懂你版IDM 6.25 build 23推荐
- CodeForces 175D Plane of Tanks: Duel (概率)
- UILabel,文字添加下划线,中划线
- 关于UINavigationBar加载不规则的图片的总结
- Css3 Media Query实现响应式的方法总结
- [leetcode-375]Guess Number Higher or Lower II(java)
- ueditor使用
- LeetCode 232. Implement Queue using Stacks
- UGUI工厂
- Qt Quick<OpacityMask> 圆角图片、异形图片的合成
- iOS开发 UITextFild/TextView限制字数(含联想词汇)
- LeetCode 347. Top K Frequent Elements
- ueditor富文本的使用以及“未找到上传文件”时的解决办法
- Fabric defect inspection using prior knowledge guided least squares regression
- uImage在内存中无法正常启动——UBoot-2010.06在TQ2440上的移植--机器码配对
- uImage在内存中无法正常启动——UBoot-2010.06在TQ2440上的移植--机器码配对
- uImage在内存中无法正常启动——UBoot-2010.06在TQ2440上的移植--机器码配对
- uImage在内存中无法正常启动——UBoot-2010.06在TQ2440上的移植--机器码配对
- uImage在内存中无法正常启动——UBoot-2010.06在TQ2440上的移植--机器码配对