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

 1 #import "MainViewController.h"
 2 
 3 @interface MainViewController ()
 4 // 延展 :管理类私有的属性和方法
 5 @end
 6 
 7 @implementation MainViewController
 8 // 指派初始化方法
 9 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
10 {
11     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
12     if (self) {
13         // Custom initialization
14         // 数据的处理 在初始化方法中写
15     }
16     return self;
17 }
18 // 视图结束加载
19 // viewController自带的view加载完毕时候调用
20 - (void)viewDidLoad
21 {
22     [super viewDidLoad];
23     // Do any additional setup after loading the view.
24     // 一般的试图操作(添加视图 改变视图设置)都在这个方法中
25     self.view.backgroundColor = [UIColor redColor];
26     
27     UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
28     button.frame = CGRectMake(20, 120, 280, 30);
29     [button setTitle:@"点 击" forState:UIControlStateNormal];
30     [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
31     [self.view addSubview:button];
32     NSLog(@"%s", __FUNCTION__);
33 
34 }
35 
36 
37 // button响应方法
38 - (void)buttonClicked:(UIButton *)button
39 {
40     // 弹出新的视图控制器
41     // 1.创建第二个试图控制器
42     SecondViewController *secondVC = [[SecondViewController alloc] init];
43     // 2.弹出
44     // 参数1:需要弹出的viewController
45     // 参数2:是否需要动画
46     // 参数3:弹出执行完毕后 执行块(Block)里的代码
47     [self presentViewController:secondVC animated:YES completion:^{
48         // code
49     }];
50     [secondVC release];
51 }
52 // viewController生命周期 方法
53 // 视图view已经出现
54 -(void)viewDidAppear:(BOOL)animated
55 {
56     [super viewDidAppear:animated];
57     NSLog(@"%s", __FUNCTION__);
58 }
59 -(void)viewWillAppear:(BOOL)animated
60 {
61     [super viewWillAppear:animated];
62     NSLog(@"%s", __FUNCTION__);
63 }
64 -(void)viewWillDisappear:(BOOL)animated
65 {
66     [super viewWillDisappear:animated];
67     NSLog(@"%s", __FUNCTION__);
68 }
69 -(void)viewDidDisappear:(BOOL)animated
70 {
71     [super viewDidDisappear:animated];
72     NSLog(@"%s", __FUNCTION__);
73 }
74 // 收到内存警告的时候 会调用这个方法
75 - (void)didReceiveMemoryWarning
76 {
77     [super didReceiveMemoryWarning];
78     // Dispose of any resources that can be recreated.
79     NSLog(@"%s", __FUNCTION__);
80 }
81 
82 /*
83 #pragma mark - Navigation
84 
85 // In a storyboard-based application, you will often want to do a little preparation before navigation
86 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
87 {
88     // Get the new view controller using [segue destinationViewController].
89     // Pass the selected object to the new view controller.
90 }
91 */
92 
93 @end

 

posted @ 2016-06-06 15:22  超级马力  阅读(282)  评论(0编辑  收藏  举报