UINavigationController導(dǎo)航視圖控制器(17-08-07)

//
//  AppDelegate.m
//  UI03_導(dǎo)航視圖控制器
//
//  Created by lanou3g on 17/8/7.
//  Copyright ? 2017年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    RootViewController *rootViewController = [[RootViewController alloc] init];
    rootViewController.title = @"首頁(yè)";
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.window.rootViewController = navigationController;
    
    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

//
//  RootViewController.m
//  UI03_導(dǎo)航視圖控制器
//
//  Created by lanou3g on 17/8/7.
//  Copyright ? 2017年 lanou3g. All rights reserved.
//

#import "RootViewController.h"
#import "SecondViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //將navigationBar的半透明小效果關(guān)掉
    self.navigationController.navigationBar.translucent = NO;
    //改變navigationBar的顏色
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(150, 100, 50, 30);
    button.backgroundColor = [UIColor blueColor];
    [button setTitle:@"push" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
}

- (void)buttonAction:(UIButton *)button {
    SecondViewController *secondViewCotroller = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondViewCotroller animated:YES];
    self.navigationController.navigationBarHidden = 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

//
//  SecondViewController.m
//  UI03_導(dǎo)航視圖控制器
//
//  Created by lanou3g on 17/8/7.
//  Copyright ? 2017年 lanou3g. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor purpleColor];
    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(150, 100, 50, 30);
//    button.backgroundColor = [UIColor blueColor];
//    [button setTitle:@"返回" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(100, 100, 100, 100);
    button1.backgroundColor = [UIColor redColor];
    [button1 setTitle:@"pop" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
}


- (void)button1Action:(UIButton *)button1 {
    [self.navigationController popToRootViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = NO;
}

- (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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末舶掖,一起剝皮案震驚了整個(gè)濱河市什猖,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌贬媒,老刑警劉巖密强,帶你破解...
    沈念sama閱讀 212,185評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件四敞,死亡現(xiàn)場(chǎng)離奇詭異桐玻,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)冲秽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,445評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén)舍咖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人锉桑,你說(shuō)我怎么就攤上這事排霉。” “怎么了民轴?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,684評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵攻柠,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我后裸,道長(zhǎng)瑰钮,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,564評(píng)論 1 284
  • 正文 為了忘掉前任微驶,我火速辦了婚禮浪谴,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘因苹。我一直安慰自己苟耻,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,681評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布扶檐。 她就那樣靜靜地躺著凶杖,像睡著了一般。 火紅的嫁衣襯著肌膚如雪款筑。 梳的紋絲不亂的頭發(fā)上智蝠,一...
    開(kāi)封第一講書(shū)人閱讀 49,874評(píng)論 1 290
  • 那天腾么,我揣著相機(jī)與錄音,去河邊找鬼杈湾。 笑死哮翘,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的毛秘。 我是一名探鬼主播,決...
    沈念sama閱讀 39,025評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼阻课,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼叫挟!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起限煞,我...
    開(kāi)封第一講書(shū)人閱讀 37,761評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤抹恳,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后署驻,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體奋献,經(jīng)...
    沈念sama閱讀 44,217評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,545評(píng)論 2 327
  • 正文 我和宋清朗相戀三年旺上,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了瓶蚂。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,694評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡宣吱,死狀恐怖窃这,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情征候,我是刑警寧澤杭攻,帶...
    沈念sama閱讀 34,351評(píng)論 4 332
  • 正文 年R本政府宣布,位于F島的核電站疤坝,受9級(jí)特大地震影響兆解,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜跑揉,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,988評(píng)論 3 315
  • 文/蒙蒙 一锅睛、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧历谍,春花似錦衣撬、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,778評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至甜无,卻和暖如春扛点,著一層夾襖步出監(jiān)牢的瞬間哥遮,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,007評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工陵究, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留眠饮,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,427評(píng)論 2 360
  • 正文 我出身青樓铜邮,卻偏偏與公主長(zhǎng)得像仪召,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子松蒜,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,580評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容