UINavigationController 導航控制器,ledcontroller控制器

來源:互聯網
上載者:User

UINavigationController 導航控制器,ledcontroller控制器

一、導航視圖控制器

1.管理檢視控制器

2.控制視圖控制器之間的跳轉

3.是以壓棧和出棧的形式來管理檢視控制器

4.導航視圖控制器必須要設定根視圖控制器

5.導航是視圖控制器包含UINavigationBar,而且UINAvigationBar是被每個視圖控制器倆管理的

UINavigationBar包含NavigationItem(一個標題,兩個按鈕)

6.push壓棧是要alloc新對象來顯示,POP出棧是返回已經存在的對象,所以不要alloc

//初始化根視圖

FirstViewController *firstViewController =[[FirstViewController alloc] init];

//建立一個導航視圖控制器,並且設定其根視圖控制器

UINavigationController *navigationController =[[UINavigationController  alloc] initWithRootViewController:firstViewController];

//如果使用導航視圖控制器來管理檢視,那麼就不要使用firstViewController作為window的根視圖,使用導航視圖控制。因為導航視圖控制器已經接管了視圖

self.window.rootViewController   =navigationController;

//因為UIViewController的懶載入機制 所以必須使用其view的時候才會去調用一系列的view的建立和顯示過程

//試圖控制器的建立 相當於在記憶體建立其對象

SecondViewController *secondViewController =[[SecondViewController alloc] init];

//隱藏導航條

navigationController.navigationBar.hidden=YES;

//以壓棧的形式把secondViewController放入導航視圖控制器中

[self.navigationController pushViewController:secondViewController animated:YES];

//pop當前對象到上個視圖

[self.navigationController popViewControllerAnimated:YES];

//pop到根試圖

  [self.navigationController popToRootViewControllerAnimated:YES];

//pop指定的視圖控制器

 

NSArray *array =  self.navigationController.viewControllers;

[self.navigationController popToViewController:[array objectAtIndex:0] animated:YES];

輸出數組只能元素的資訊(記憶體位址和所屬類型)

NSLog(@"%@",[array objectAtIndex:0]);

輸出數組中的元素個數

 NSLog(@"----->>>>>>~~~%d",[array count]);

 

二、UIBarButtonItem

//建立一個UIBarButtonItem

 UIBarButtonItem *rightBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"

設定標題

" style:UIBarButtonItemStylePlain(設定類型) target:self(設定目標) action:@selector(btnCilck:)(Binder 方法)];

//設定item 右按鈕

    self.navigationItem.rightBarButtonItem =rightBarButtonItem;

三、生命週期傳值

//給FirstViewController對象屬性value 賦值的過程

-(void)viewWillDisappear:(BOOL)animated

{

    UITextField *textFiled =(UITextField *)[self.view viewWithTag:100];

    //獲得當前置航試圖控制器如包含的所有試圖控制器對象

    NSArray *array = self.navigationController.viewControllers;

    //獲得根試圖對象

    FirstViewController *  fv =  [array  objectAtIndex:0];

    //輸入框內容賦值給根試圖屬性

    fv.value  = textFiled.text;

    NSLog(@"我區~~~");

    [super viewWillDisappear:YES];

}

 

//使用給FirstViewController對象屬性value 把值傳過來

-(void)viewWillAppear:(BOOL)animated

{

    NSLog(@"我有回來了~~");

    UITextField *textFiled =(UITextField *)[self.view viewWithTag:100];

    textFiled.text =self.value;

    [super viewWillAppear:YES];

}

 四、生命週期

//loadView 和viewDidLoad只會載入一次 在一個試圖控制器的生命週期中

//viewWillAppear和viewDidAppear 只要執行View顯示功能就會執行

//當前試圖正在載入

-(void)loadView

{

    NSLog(@"當前試圖正在載入");

    [super loadView];

}

 

//當前試圖載入完畢

- (void)viewDidLoad

{

    [super viewDidLoad];

NSLog(@"當前試圖載入完畢");

}

//當前試圖將要顯示

-(void)viewWillAppear:(BOOL)animated

{

    NSLog(@"當前試圖將要顯示");

    [super viewWillAppear:YES];

}

 

//當前試圖已經顯示

-(void)viewDidAppear:(BOOL)animated

{

    NSLog(@"當前試圖已經顯示");

    [super viewDidAppear:YES];

}

//當前試圖將要消失

-(void)viewWillDisappear:(BOOL)animated

{

    NSLog(@"---->>>當前試圖將要消失");

    [super viewWillDisappear:YES];

}

//當前試圖已經消失

-(void)viewDidDisappear:(BOOL)animated

{

    NSLog(@"---->>>當前試圖已經消失");

    [super viewDidDisappear:YES];

}

 

//試圖控制機對象被釋放的時候會自動調用此方法(手動管理記憶體)

-(void)dealloc

{

    NSLog(@"試圖控制器被釋放了");

    [super dealloc];

}

//

幹掉試圖控制器

[幹掉第二個視圖控制器(最後一次返回)release];

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.