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

来源:互联网 发布:剑三好友招募积分算法 编辑:程序博客网 时间:2024/04/30 22:36

#import "MainViewController.h"


@interface MainViewController ()

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

@end


@implementation MainViewController

// 指派初始化方法

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

{

    self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

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

    }

    return self;

}

// 视图结束加载

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

- (void)viewDidLoad

{

    [superviewDidLoad];

    // Do any additional setup after loading the view.

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

    self.view.backgroundColor = [UIColorredColor];

    

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];

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

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

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

    [self.viewaddSubview:button];

    NSLog(@"%s",__FUNCTION__);


}



// button响应方法

- (void)buttonClicked:(UIButton *)button

{

    //弹出新的视图控制器

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

    SecondViewController *secondVC = [[SecondViewControlleralloc] init];

    // 2.弹出

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

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

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

    [selfpresentViewController:secondVC animated:YEScompletion:^{

        // 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

{

    [superdidReceiveMemoryWarning];

    // 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
原创粉丝点击