• UI基础 视图控制器


    RootViewController

    #import "RootViewController.h"
    #import "SecondViewController.h"
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        NSLog(@"视图已经加载好了,可以用了");
        self.view.backgroundColor=[UIColor redColor];
        UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];
        button.frame=CGRectMake(10, 100, 100, 50);
        [self.view addSubview:button];
        button.backgroundColor=[UIColor yellowColor];
        [button addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    -(void)jump
    {
    //    点击按钮到第二个页面
    //    跳到哪
        SecondViewController* second=[[SecondViewController alloc]init];
        
    //    怎么跳
        second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
    //
        [self presentViewController:second animated:YES completion:^{
            NSLog(@"跳转完成");
        }];
        
        
        
    }
    
    -(void)loadView
    {
        
        [super loadView];
        NSLog(@"视图正在加载");
        
    }
    
    
    -(void)viewWillAppear:(BOOL)animated
    {
        
        NSLog(@"视图将要出现");
        
    }
    
    -(void)viewDidAppear:(BOOL)animated
    {
        NSLog(@"视图已经出现");
        
    }
    
    -(void)viewWillDisappear:(BOOL)animated
    {
        NSLog(@"视图将要消失");
        
    }
    -(void)viewDidDisappear:(BOOL)animated
    {
        NSLog(@"视图已经消失");
    }
    
    
    
    
    @end

    SecondViewController

    #import "SecondViewController.h"
    
    @interface SecondViewController ()
    
    @end
    
    @implementation SecondViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.view.backgroundColor=[UIColor blueColor];
        
        UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];
        button.frame=CGRectMake(10, 100, 100, 50);
        [self.view addSubview:button];
        button.backgroundColor=[UIColor yellowColor];
        [button addTarget:self action:@selector(jumpback) forControlEvents:UIControlEventTouchUpInside];
        
        
        
    }
    
    -(void)jumpback
    {
        
        [self dismissViewControllerAnimated:YES completion:^{
            NSLog(@"返回完成");
        }];
    }
    
    @end
  • 相关阅读:
    π框架参数规则(正则表达式验证)
    SQL查询优化的一些建议
    phalApi框架打印SQL语句
    phpstorm注册码
    phalApi数据库操作
    内容的全局搜索
    xampp虚拟主机的配置
    navicat自动备份数据
    IOC和AOP扩展
    Spring AOP
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13348167.html
Copyright © 2020-2023  润新知