#import "ViewController.h"
#import "SecondViewController.h" @interface ViewController () @end @implementation ViewController // 视图控制器的生命周期
// 视图控制器的加载方法
// 模态视图方法 /*
// 视图控制器的加载方法
- (instancetype)init
{
self = [super init];
if (self) {
// 属性、成员变量
// 千万不要在这个地方初始化控件
}
return self;
} - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
// 初始化控件(用nib文件创建的控件)
// IB (.Xib文件) 没有stroyboard之前用的 这个文件叫nib文件
} - (void)loadView
{
//初始化试图用
}
*/ // 视图加载完成时调用,视图控制器当中(伪第一)调用的方法
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad"); self.view.backgroundColor = [UIColor cyanColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"next" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor orangeColor]];
[btn addTarget:self action:@selector(modelMethod) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; }
#pragma mark - life Cycle
// 视图(每次)将要出现的时候调用
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"viewWillAppear"); }
// 视图(每次?)出现完成的时候调用
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"veiwDidAppear"); }
// 视图(每次)将要消失的时候调用
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(@"viewWillDisappear"); }
// 视图消失完成之后时候调用
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSLog(@"viewDidDisappear"); } #pragma mark - Model View Method(模态视图方法)
- (void)modelMethod
{
// 视图切换,切换到下一个视图
SecondViewController *secondVC = [[SecondViewController alloc] init];
// // 伪翻页
// secondVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
// // 模态方法跳入
// [self presentViewController:secondVC animated:YES completion:nil]; //屌丝方法
[self.view addSubview:secondVC.view];
[self addChildViewController:secondVC];
} #pragma mark - other System Method
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
} @end
#import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad"); self.view.backgroundColor = [UIColor darkGrayColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setFrame:CGRectMake(, , , )];
[btn setTitle:@"back" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor whiteColor]];
[btn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; }
- (void)backMethod
{
// 模态方法跳出
// [self dismissViewControllerAnimated:YES completion:nil]; //屌丝方法跳出
[self.view removeFromSuperview];
[self removeFromParentViewController];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}