成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iOS學習之UINavigationController詳解與使用(二)

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

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

1、RootView 跳到SecondView

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

2、為Button 添加點擊事件,實現跳轉

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

在RootViewController.m中實現代碼,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 按鈕,出現

這就是SecondView了。

3、添加segmentedController

在nav bar這樣的效果是如何實現的呢?

這就是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:的實現

  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. }   

這樣就能響應雞翅和排骨按鈕了

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學習之UINavigationController詳解與使用(一)添加UIBarButtonItem

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

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

責任編輯:閆佳明 來源: csdn
相關推薦

2013-04-02 10:36:43

iOS學習UINavigatioToolBar

2013-04-02 10:15:45

iOS學習UINavigatio添加UIBarButt

2011-08-02 11:07:42

iOS開發 UIWebView

2015-07-09 13:47:37

IOSFMDB

2011-07-26 17:31:52

iOS 設計模式

2011-08-16 14:59:31

IOS開發ViewDidUnloiOS 5

2011-08-23 13:56:12

MySQLConnection

2019-01-04 15:14:18

2019-02-12 15:04:09

2010-05-14 16:57:01

Subversion命

2011-08-02 11:17:13

iOS開發 View

2021-08-25 07:43:17

AndroidSurfaceViewTextureView

2011-08-16 15:35:50

MySQLSELECT語句FROM子句

2011-08-16 16:10:12

MySQLORDER BY子句GROUP BY子句

2011-08-03 17:32:17

IOS UIScrollVi touch

2010-07-06 10:56:32

UML圖詳解

2009-01-05 15:55:00

軟考網工負載均衡

2012-05-10 08:55:11

Linuxuniq

2023-09-27 09:18:35

2011-07-18 14:39:53

iPhone SDK UIKit
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 狠狠骚 | 免费精品在线视频 | 国产亚洲日本精品 | 国产精品久久久久久久久久 | 亚洲一区 | 亚洲 欧美 另类 综合 偷拍 | 国产精品久久久乱弄 | 国产精品久久久久久一区二区三区 | 国产日韩欧美综合 | 亚洲精品在线免费观看视频 | 欧美精品一区二区三区在线 | 中文字幕av中文字幕 | 亚洲欧美日本国产 | 欧美激情综合 | 欧日韩在线观看 | 亚洲精品在线看 | 性欧美精品一区二区三区在线播放 | 在线观看午夜视频 | 一级亚洲| 欧美视频二区 | 亚洲欧洲视频 | 一区二区在线不卡 | 一区二区三区视频在线免费观看 | 亚欧精品| 在线观看www | 亚洲国产激情 | 日韩一级电影免费观看 | 久久国产精品免费一区二区三区 | 久久久免费| 亚洲午夜av久久乱码 | 欧美成人h版在线观看 | 欧美日韩亚洲国产 | 国产精品久久久 | 国产成人精品免费视频大全最热 | 国产在线色| 麻豆一区 | 日韩免费毛片视频 | 自拍视频网站 | 男人av的天堂 | 欧美日韩综合精品 | 亚洲免费片 |