UIViewController 登录,生命周期,正向传值

//
//  ZKAppDelegate.m
//  01-UIViewcontrollerDemo
//

#import "ZKAppDelegate.h"
#import "ZKLoginViewController.h"
@implementation ZKAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    //UIViewController:作用:管理View,处理与view相关的事情。

    //例子:蜜蜂阅读器
    //包括三个界面:登陆界面-主界面-配置界面
    //之前:使用addSubview:方法直接将三个界面(view)添加为window的子视图,达到显示的目的

    //现在:我们要创建viewController,将view的相关内容交给viewController来处理,将viewController添加为window的根视图控制器,达到间接显示的目的

    //注意:一个viewController对应一个view

    //1.创建三个viewController
    ZKLoginViewController *login = [[ZKLoginViewController alloc]init];

    //2.将登陆视图控制器设置成window的根视图控制器
    self.window.rootViewController = login;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

//
//  ZKConfigViewController.m
//  01-UIViewcontrollerDemo
//

#import "ZKConfigViewController.h"

@interface ZKConfigViewController ()

@end

@implementation ZKConfigViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];

    //创建标签
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 40)];
    //显示
    //原来是通过添加到self.window来显示
    //现在时添加到self.view来显示   (非常重要)
    [self.view addSubview:label];

    //显示内容
    label.text = @"这里是配置界面";

    //按钮 :作用:跳转到上一个界面
    UIButton *prePast = [UIButton buttonWithType:UIButtonTypeSystem];

    prePast.frame = CGRectMake(100, 150, 120, 40);

    [prePast setTitle:@"上一页" forState:UIControlStateNormal];

    //显示
    [self.view addSubview:prePast];

    //执行跳转
    [prePast addTarget:self action:@selector(backToMain) forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.
}

-(void)backToMain{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

//
//  ZKLoginViewController.m
//  01-UIViewcontrollerDemo
//

#import "ZKLoginViewController.h"
#import "ZKMainViewController.h"
@interface ZKLoginViewController ()

@end

@implementation ZKLoginViewController

//初始化方法:(在用nib/xib等创建控制器的时候才使用) (很少使用)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
//初始化方法  (重要)(基本完成所有关于view的初始化工作)
- (void)viewDidLoad
{
    //必须写,放在最上面(重要)
    [super viewDidLoad];
    //设置当前view的背景色
    self.view.backgroundColor = [UIColor blueColor];

    //创建标签
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 40)];
    //显示
    //原来是通过添加到self.window来显示
    //现在时添加到self.view来显示   (非常重要)
    [self.view addSubview:label];

    //显示内容
    label.text = @"这里是登录界面";

    //按钮 :作用:跳转到下一个界面
    UIButton *nextPast = [UIButton buttonWithType:UIButtonTypeSystem];

    nextPast.frame = CGRectMake(100, 150, 120, 40);

    [nextPast setTitle:@"下一页" forState:UIControlStateNormal];

    //显示
    [self.view addSubview:nextPast];

    //执行跳转
    [nextPast addTarget:self action:@selector(intoMain) forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.
}

-(void)intoMain{
    NSLog(@"进入下一页");
    //创建main对象
    ZKMainViewController *main = [[ZKMainViewController alloc]init];

    //跳转动画
    main.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    //完成页面的跳转   (模态跳转)
    //这里是一个栈结构  我们看到的肯定是栈顶元素。
    [self presentViewController:main animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

//
//  ZKMainViewController.m
//  01-UIViewcontrollerDemo
//

#import "ZKMainViewController.h"
#import "ZKConfigViewController.h"
@interface ZKMainViewController ()

@end

@implementation ZKMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor greenColor];

    //创建标签
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 40)];
    //显示
    //原来是通过添加到self.window来显示
    //现在时添加到self.view来显示   (非常重要)
    [self.view addSubview:label];

    //显示内容
    label.text = @"这里是主界面";

    //按钮 :作用:跳转到上一个界面
    UIButton *prePast = [UIButton buttonWithType:UIButtonTypeSystem];

    prePast.frame = CGRectMake(100, 150, 120, 40);

    [prePast setTitle:@"上一页" forState:UIControlStateNormal];

    //显示
    [self.view addSubview:prePast];

    //执行跳转
    [prePast addTarget:self action:@selector(backToLogin) forControlEvents:UIControlEventTouchUpInside];

    // 第二个按钮 (跳到下一页)
    UIButton *nextPast = [UIButton buttonWithType:UIButtonTypeSystem];

    nextPast.frame = CGRectMake(100, 200, 120, 40);

    [nextPast setTitle:@"下一页" forState:UIControlStateNormal];

    //显示
    [self.view addSubview:nextPast];

    //执行跳转
    [nextPast addTarget:self action:@selector(intoConfig) forControlEvents:UIControlEventTouchUpInside];

    // Do any additional setup after loading the view.
}

-(void)backToLogin{
    //返回到上一个界面,执行的退栈操作
    //注意:dismiss与present方法要结合使用
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)intoConfig{
    ZKConfigViewController *config = [[ZKConfigViewController alloc]init];

    config.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    //压栈
    [self presentViewController:config animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end