//
// AppDelegate.m
// uinavigationcontrollerdemo
//
// Created by panba on 15-12-27.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "AppDelegate.h"
#import "rootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
rootViewController *rvc = [[rootViewController alloc]init];
UINavigationController *nvaContorller = [[UINavigationController alloc]initWithRootViewController:rvc];
self.window.rootViewController = nvaContorller ;
rvc.navigationController.toolbarHidden = YES;
[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
//
// ViewController2.m
// uinavigationcontrollerdemo
//
// Created by panba on 15-12-28.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "ViewController2.h"
#import "ViewController3.h"
@interface ViewController2 ()
@end
@implementation ViewController2
- (instancetype)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 blueColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10, 100, 300, 50);
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@"push到vc3" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UIButton *popbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
popbtn.frame = CGRectMake(10, 200, 300, 50);
popbtn.backgroundColor = [UIColor orangeColor];
[popbtn setTitle:@"popvc2" forState:UIControlStateNormal];
[self.view addSubview:popbtn];
[popbtn addTarget:self action:@selector(popClick:) forControlEvents:UIControlEventTouchUpInside];
// Do any additional setup after loading the view.
}
-(void)btnClick:(UIButton *)btn
{
ViewController3 *vc3 = [[ViewController3 alloc]init];
[self.navigationController pushViewController:vc3 animated:YES];
}
-(void)popClick:(UIButton *)popbtn
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
//
// rootViewController.m
// uinavigationcontrollerdemo
//
// Created by panba on 15-12-27.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "rootViewController.h"
#import "ViewController2.h"
@interface rootViewController ()
@end
@implementation rootViewController
- (instancetype)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];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10, 100, 300, 50);
btn.backgroundColor = [UIColor blueColor];
[btn setTitle:@"push到vc2" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view.
}
-(void)btnClick:(UIButton *)btn
{
ViewController2 *vc2 = [[ViewController2 alloc]init];
[self.navigationController pushViewController:vc2 animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
//
// ViewController3.m
// uinavigationcontrollerdemo
//
// Created by panba on 15-12-28.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "ViewController3.h"
#import "ViewController4.h"
@interface ViewController3 ()
@end
@implementation ViewController3
- (instancetype)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 yellowColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10, 100, 300, 50);
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@"push到vc4" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view.
}
-(void)btnClick:(UIButton *)btn
{
ViewController4 *vc4 = [[ViewController4 alloc]init];
[self.navigationController pushViewController:vc4 animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
//
// ViewController4.m
// uinavigationcontrollerdemo
//
// Created by panba on 15-12-29.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "ViewController4.h"
#import "ViewController2.h"
@interface ViewController4 ()
@end
@implementation ViewController4
- (instancetype)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 purpleColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10, 100, 300, 50);
btn.backgroundColor = [UIColor orangeColor];
btn.tag =1;
[btn setTitle:@"push到root" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
UIButton *popbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
popbtn.frame = CGRectMake(10, 200, 300, 50);
popbtn.backgroundColor = [UIColor orangeColor];
[popbtn setTitle:@"pop到vc2" forState:UIControlStateNormal];
popbtn.tag = 2;
[self.view addSubview:popbtn];
[popbtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
// Do any additional setup after loading the view.
}
-(void)btnClick:(UIButton *)btn
{
UIButton *mybtn = (UIButton *)btn;
if (mybtn.tag ==1) {
//回到主视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];
}
else if(mybtn.tag ==2)
{
//跳转到vc2
NSArray *array = self.navigationController.viewControllers;
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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