UI 指派初始化方法 视图控制器 button响应方法

#import "MainViewController.h"


@interface MainViewController ()

// 延展 :管理类私有的属性和方法

@end


@implementation MainViewController

// 指派初始化方法

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

        // 数据的处理 在初始化方法中写

    }

    return self;

}

// 视图结束加载

// viewController自带的view加载完毕时候调用

- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    // 一般的试图操作(添加视图 改变视图设置)都在这个方法中

    self.view.backgroundColor = [UIColor redColor];

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

    button.frame = CGRectMake(20, 120, 280, 30);

    [button setTitle:@" " forState:UIControlStateNormal];

    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    NSLog(@"%s", __FUNCTION__);


}



// button响应方法

- (void)buttonClicked:(UIButton *)button

{

    // 弹出新的视图控制器

    // 1.创建第二个试图控制器

    SecondViewController *secondVC = [[SecondViewController alloc] init];

    // 2.弹出

    // 参数1:需要弹出的viewController

    // 参数2:是否需要动画

    // 参数3:弹出执行完毕后 执行块(Block)里的代码

    [self presentViewController:secondVC animated:YES completion:^{

        // code

    }];

    [secondVC release];

}

// viewController生命周期 方法

// 视图view已经出现

-(void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    NSLog(@"%s", __FUNCTION__);

}

-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    NSLog(@"%s", __FUNCTION__);

}

-(void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    NSLog(@"%s", __FUNCTION__);

}

-(void)viewDidDisappear:(BOOL)animated

{

    [super viewDidDisappear:animated];

    NSLog(@"%s", __FUNCTION__);

}

// 收到内存警告的时候 会调用这个方法

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    NSLog(@"%s", __FUNCTION__);

}


/*

#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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值