(002)UIViewController跳转方式1

#import <UIKit/UIKit.h>

@class AlinViewController;

@interface AlinAppDelegate : UIResponder <UIApplicationDelegate>
{
    //UIWindow *win;
    UIViewController *firstViewController;
    UIViewController *secondViewController;
}

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) AlinViewController *viewController;

@end
AlinAppDelegate.h
#import "AlinAppDelegate.h"

#import "AlinViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

@implementation AlinAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   
    //self.viewController = [[AlinViewController alloc] initWithNibName:@"AlinViewController" bundle:nil];
    //self.window.rootViewController = self.viewController;
    
    firstViewController = [[FirstViewController alloc] init];
    secondViewController = [[SecondViewController alloc] init];
    [self.window addSubview:firstViewController.view];
    [self.window addSubview:secondViewController.view];
    [self.window bringSubviewToFront:firstViewController.view];
    
    [self.window makeKeyAndVisible];
    return YES;
}
AlinAppDelegate.m
#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
    label.text = @"FirstViewController";
    label.backgroundColor = [UIColor whiteColor];
    label.textColor = [UIColor blackColor];
    label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:label];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"跳转到界面2" forState:UIControlStateNormal];
    [button sizeToFit];
    CGPoint point = self.view.center;
    point.y += 50;
    button.center = point;
    button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [button addTarget:self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

-(void)buttonDidPush
{
    [self.view.window sendSubviewToBack:self.view];
}

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

@end
FirstViewController
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
    label.text = @"SecondViewController";
    label.backgroundColor = [UIColor whiteColor];
    label.textColor = [UIColor blackColor];
    label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:label];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"跳转到界面1" forState:UIControlStateNormal];
    [button sizeToFit];
    CGPoint point = self.view.center;
    point.y += 50;
    button.center = point;
    button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [button addTarget:self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

-(void)buttonDidPush
{
    [self.view.window sendSubviewToBack:self.view];
}

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

@end
SecondViewController

 

posted @ 2013-08-07 10:51  雪中飞雁  阅读(85)  评论(0)    收藏  举报