#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