偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iOS學(xué)習(xí)之UINavigationController詳解與使用(二)

移動開發(fā) iOS
本文詳細介紹了iOS學(xué)習(xí)之中的UINavigationController詳解與使用,以及頁面切換和segmentedController,希望對大家的iOS開發(fā)學(xué)習(xí)有所幫助。

iOS學(xué)習(xí)之UINavigationController詳解與使用(一)添加UIBarButtonItem是上篇,我們接著講UINavigationController的重要作用,頁面的管理和切換。

1、RootView 跳到SecondView

首先我們需要新一個View。新建SecondView,按住Command鍵然后按N,彈出新建頁面,我們新建SecondView

2、為Button 添加點擊事件,實現(xiàn)跳轉(zhuǎn)

在RootViewController.xib中和RootViewController.h文件建立連接

在RootViewController.m中實現(xiàn)代碼,alloc一個SecondViewController,用pushViewController到navigationController中去,并為

SecondViewController這是title為    secondView.title =@"Second View"; 默認情況下,titie為下個頁面返回按鈕的名字。

  1. - (IBAction)gotoSecondView:(id)sender {   
  2.     SecondViewController *secondView = [[SecondViewController alloc] init];   
  3.     [self.navigationController pushViewController:secondView animated:YES];   
  4.     secondView.title = @"Second View";   
  5. }   

這是點擊GotoSecondView 按鈕,出現(xiàn)

這就是SecondView了。

3、添加segmentedController

在nav bar這樣的效果是如何實現(xiàn)的呢?

這就是segmentedController。

3.1在RootViewController.m的viewDidLoad添加如下代碼:

  1. NSArray *array = [NSArray arrayWithObjects:@"雞翅",@"排骨", nil];   
  2.    UISegmentedControl *segmentedController = [[UISegmentedControl alloc] initWithItems:array];   
  3.    segmentedController.segmentedControlStyle = UISegmentedControlSegmentCenter;   
  4.    [segmentedController addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];   
  5.    self.navigationItem.titleView = segmentedController;  

3.2[segmentedController addTarget:selfaction:的實現(xiàn)

  1. -(void)segmentAction:(id)sender   
  2. {   
  3.     switch ([sender selectedSegmentIndex]) {   
  4.         case 0:   
  5.         {   
  6.             UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你點擊了雞翅" delegate:self  cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];   
  7.             [alter show];   
  8.         }   
  9.         break;   
  10.     case 1:   
  11.         {   
  12.             UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你點擊了排骨" delegate:self  cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];   
  13.             [alter show];   
  14.         }   
  15.         break;      
  16.         default:   
  17.             break;   
  18.     }   
  19. }   

這樣就能響應(yīng)雞翅和排骨按鈕了

4、自定義backBarButtonItem

左上角的返回上級View的barButtonitem的名字是上級目錄的Title,如果title或者適合做button的名字,怎么辦呢?我們可以自己定義

代碼如下:

  1. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"根視圖" style:UIBarButtonItemStyleDone target:nil action:nil];   
  2.    self.navigationItem.backBarBu 

效果:

6、自定義title

UINavigationController的title可以用別view替代,比如用UIButton UILable等,下面我用UIButton.

在SecondViewController.m中添加下面如下。

  1. - (void)viewDidLoad   
  2. {   
  3.     [super viewDidLoad];   
  4.     UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];   
  5.     [button setTitle: @"自定義title" forState: UIControlStateNormal];   
  6.     [button sizeToFit];   
  7.     self.navigationItem.titleView = button;}   

運行程序,goto secondView,運行效果

下篇文件講下Navigation 的Toobar如何顯示和如何自己定義。

上篇:iOS學(xué)習(xí)之UINavigationController詳解與使用(一)添加UIBarButtonItem

下篇:iOS學(xué)習(xí)之UINavigationController詳解與使用(三)ToolBar

著作權(quán)聲明:本文由http://blog.csdn.net/totogo2010/原創(chuàng),歡迎轉(zhuǎn)載分享。請尊重作者勞動,轉(zhuǎn)載時保留該聲明和作者博客鏈接,謝謝

責任編輯:閆佳明 來源: csdn
相關(guān)推薦

2013-04-02 10:36:43

iOS學(xué)習(xí)UINavigatioToolBar

2013-04-02 10:15:45

iOS學(xué)習(xí)UINavigatio添加UIBarButt

2011-08-02 11:07:42

iOS開發(fā) UIWebView

2015-07-09 13:47:37

IOSFMDB

2011-07-26 17:31:52

iOS 設(shè)計模式

2011-08-16 14:59:31

IOS開發(fā)ViewDidUnloiOS 5

2019-02-12 15:04:09

2011-08-23 13:56:12

MySQLConnection

2019-01-04 15:14:18

2010-05-14 16:57:01

Subversion命

2011-08-02 11:17:13

iOS開發(fā) View

2011-08-16 16:10:12

MySQLORDER BY子句GROUP BY子句

2021-08-25 07:43:17

AndroidSurfaceViewTextureView

2011-08-16 15:35:50

MySQLSELECT語句FROM子句

2011-08-03 17:32:17

IOS UIScrollVi touch

2012-05-10 08:55:11

Linuxuniq

2023-09-27 09:18:35

2013-01-30 15:36:03

NFC移動支付藍牙

2010-07-06 10:56:32

UML圖詳解

2011-07-18 14:39:53

iPhone SDK UIKit
點贊
收藏

51CTO技術(shù)棧公眾號