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

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

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

iOS學習之UINavigationController詳解與使用(二)頁面切換和segmentedController  接上篇,我們接著講Navigation 的Toolbar。

1、顯示Toolbar 

在RootViewController.m的- (void)viewDidLoad方法中添加代碼,這樣Toobar就顯示出來了。

  1. [self.navigationController  setToolbarHidden:NO animated:YES];  

2、在ToolBar上添加UIBarButtonItem

新建幾個UIBarButtonItem,然后以數組的形式添加到Toolbar中

  1. UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];   
  2.     UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];   
  3.     UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];   
  4.     UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];   
  5.     UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];   
  6.     [self setToolbarItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];   

效果:

 

注意:用   [self.navigationController.toolbar setItems:(NSArray *) animated:<#(BOOL)#>]這個方法添加item是不起效果的。下面我動態自己添加Toolbar時,這個才起效果。

3、動態添加Toolbar

我們在SecondView添加動態的Toolbar。

在SecondViewController.h添加

  1. #import <UIKit/UIKit.h>   
  2. @interface SecondViewController : UIViewController   
  3. {   
  4.     UIToolbar *toolBar;   
  5. }   
  6. @end   

在SecondViewController.m添加

  1. - (void)viewDidLoad   
  2. {   
  3.     [super viewDidLoad];   
  4.     [self.navigationController  setToolbarHidden:YES animated:YES];   
  5.     UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(gotoThridView:)];   
  6.     toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - toolBar.frame.size.height - 44.0, self.view.frame.size.width, 44.0)];   
  7.     [toolBar setBarStyle:UIBarStyleDefault];   
  8.     toolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;   
  9.     [toolBar setItems:[NSArray arrayWithObject:addButton]];   
  10.     [self.view addSubview:toolBar];   
  11.     // Do any additional setup after loading the view from its nib.   
  12. }   

先把RootView時顯示的Toobar隱藏

    [self.navigationController setToolbarHidden:YESanimated:YES];然后把新建的Toolbar添加的SecondView中,并為Toobar設置了一個Item.  

    [toolBarsetItems:[NSArrayarrayWithObject:addButton]]; 

BarButtonItem用 的是UIBarButtonSystemItemSearch, 效果如下:

4、新建ThridView,從SecondView跳轉到

Commad+N新建一個ThridViewController,

這個addButton跳轉到ThridView

  1. -(void)gotoThridView:(id)sender   
  2. {   
  3.     ThridViewController *thridView = [[ThridViewController alloc] init];   
  4.     [self.navigationController pushViewController:thridView animated:YES];   
  5.     thridView.title = @"Thrid View";   
  6. }  

跳轉Second到Third效果:

到此UINavigationController練習的差不多了。

前面兩篇:

iOS學習之UINavigationController詳解與使用(一)添加UIBarButtonItem

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

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

 
著作權聲明:本文由http://blog.csdn.net/totogo2010/原創,歡迎轉載分享。請尊重作者勞動,轉載時保留該聲明和作者博客鏈接,謝謝
責任編輯:閆佳明 來源: csdn
相關推薦

2013-04-02 10:15:45

iOS學習UINavigatio添加UIBarButt

2013-04-02 10:16:34

iOS學習UINavigatio頁面切換

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

2011-08-23 13:56:12

MySQLConnection

2019-01-04 15:14:18

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移動支付藍牙

2010-07-06 10:56:32

UML圖詳解

2011-08-03 17:32:17

IOS UIScrollVi touch

2012-05-10 08:55:11

Linuxuniq

2023-09-27 09:18:35

2011-07-18 14:39:53

iPhone SDK UIKit

2022-12-22 07:40:28

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品免费观看视频 | 国产69久久精品成人看动漫 | 综合在线视频 | 国产精品无码专区在线观看 | 影视一区 | 激情六月天 | 手机av在线| 全免费a级毛片免费看视频免 | 久久av网| 日韩久草 | 精品一级| 欧美在线视频一区二区 | 九九热在线免费视频 | 一级毛片在线看 | 亚洲成人精品一区 | 午夜一级大片 | 中文字幕在线播放第一页 | 久久综合狠狠综合久久综合88 | 欧美久久一级 | 超碰欧美| 91福利电影在线观看 | 国产不卡视频 | 99视频在线 | 岛国二区 | 国产色婷婷精品综合在线播放 | 黑人精品欧美一区二区蜜桃 | 日韩精品免费 | 亚洲一区二区三区在线播放 | 国产综合视频 | 中文字幕国产第一页 | 久久精品国产免费高清 | 在线观看国产视频 | 91 在线| 日韩在线免费视频 | 免费黄色在线 | 欧美一区二区三区视频在线观看 | 伊人免费网 | 日韩国产在线 | 欧美一级欧美一级在线播放 | caoporn免费| 欧美一区二区三区在线观看视频 |