成人免费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

2019-02-12 15:04:09

2019-01-04 15:14:18

2011-08-23 13:56:12

MySQLConnection

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 16:10:12

MySQLORDER BY子句GROUP BY子句

2011-08-16 15:35:50

MySQLSELECT語句FROM子句

2013-01-30 15:36:03

NFC移動支付藍牙

2011-08-03 17:32:17

IOS UIScrollVi touch

2010-07-06 10:56:32

UML圖詳解

2012-05-10 08:55:11

Linuxuniq

2023-09-27 09:18:35

2011-07-18 14:39:53

iPhone SDK UIKit
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 九九在线精品视频 | 国产成人免费观看 | 日韩欧美二区 | 午夜影院在线 | 日本成人三级电影 | 午夜视频在线免费观看 | www.嫩草 | 亚洲成人精品免费 | 国产夜恋视频在线观看 | 精品久久久久久久久久久久久久 | 久久久久国产精品免费免费搜索 | 亚洲高清视频一区二区 | 美女久久久 | 无人区国产成人久久三区 | 性色在线 | 久久久美女 | 中文字幕第二十页 | 日韩中文字幕第一页 | 精品国产成人 | 国产在线资源 | 日本精品一区二区三区视频 | 欧美一区二区三区四区五区无卡码 | 在线观看亚 | 九九99久久| 手机日韩 | 日本韩国电影免费观看 | 在线只有精品 | 国产一区二区三区网站 | 成人免费一区二区三区牛牛 | 二区精品 | 欧美一级网站 | 日韩中文字幕视频在线观看 | 成人夜晚看av | 亚洲精品国产成人 | 国产在线一区二区 | 99久久婷婷国产综合精品电影 | 射欧美 | 欧美在线视频一区二区 | 亚洲成人自拍 | 成人国产精品久久 | 91在线电影 |