真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController

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

目前創(chuàng)新互聯(lián)建站已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、和順網(wǎng)站維護等服務(wù),公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

1、RootView 跳到SecondView

首先我們需要新一個View。新建SecondView,按住Command鍵然后按N,彈出新建頁面,我們新建SecondViewIOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController


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

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

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController


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

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

[cpp] view plaincopy
  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)

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController

這就是SecondView了。


3、添加segmentedController

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

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController

這就是segmentedController。

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

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

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

[cpp] view plaincopy
  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.         }  
  10.         break;  
  11.     case 1:  
  12.         {  
  13.             UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你點擊了排骨" delegate:self  cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];  
  14.             [alter show];  
  15.         }  
  16.         break;  
  17.           
  18.         default:  
  19.             break;  
  20.     }  
  21. }  
這樣就能響應雞翅和排骨按鈕了

4、自定義backBarButtonItem

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

代碼如下:

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

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController

6、自定義title

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

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

[cpp] view plaincopy
  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,運行效果

IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController

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

IOS學習之UINavigationController詳解與使用(三)ToolBarhttp://blog.csdn.net/duxinfeng2010/article/details/7707072




例子代碼:https://github.com/schelling/YcDemo



原博客連接地址http://blog.csdn.net/totogo2010/article/details/7682433



分享題目:IOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController
地址分享:http://weahome.cn/article/jhppch.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部