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

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

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

UINavigationController可以翻譯為導航控制器,在iOS里經常用到。

1、UINavigationController導航控制器如何使用

我們看看它的如何使用:

下 面的圖顯示了導航控制器的流程。最左側是根視圖,當用戶點擊其中的General項時 ,General視圖會滑入屏幕;當用戶繼續點擊Auto-Lock項時,Auto-Lock視圖將滑入屏幕。相應地,在對象管理上,導航控制器使用了導 航堆棧。根視圖控制器在堆棧最底層,接下來入棧的是General視圖控制器和Auto-Lock視圖控制器。可以調用 pushViewControllerAnimated:方法將視圖控制器推入棧頂,也可以調用popViewControllerAnimated:方 法將視圖控制器彈出堆棧。

上圖來自蘋果官網。

2、UINavigationController的結構組成

看下圖,UINavigationController有Navigation bar  ,Navigation View ,Navigation toobar等組成。

現在我們建立一個例子,看看如何使用UINavigationController

3、新建一個項目

命名為UINavigationControllerDemo,為了更好理解UINavigationController,我們選擇Empty Application模板

4、創建一個View Controller,命名為RootViewController:依次選擇File——New——New File,默認勾上With XIB for user interface.

選擇正確位置創建完成,這時項目里多了三個文件,分別是RootViewController.h RootViewController.m RootViewController.xib文件。

打開RootViewController.xib,添加一個按鈕控件,按鈕Button改成 :Goto SecondView,為跳轉做準備

5、打開AppDelegate.h,向其中添加屬性:

  1. @property (strong, nonatomic) UINavigationController *navController;   

添加后AppDelegate.h文件代碼如下:

  1. #import <UIKit/UIKit.h>   
  2. @class ViewController;   
  3. @interface AppDelegate : UIResponder <UIApplicationDelegate>   
  4. @property (strong, nonatomic) UIWindow *window;   
  5. @property (strong, nonatomic) ViewController *viewController;   
  6. @property (strong, nonatomic) UINavigationController *navController;   
  7. @end   

6、在AppDelegate.m 文件的didFinishLaunchingWithOptions方法中創建添加navController,RootViewController視圖。

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions   
  2. {   
  3.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];   
  4.     RootViewController *rootView = [[RootViewController alloc] init];   
  5.     rootView.title = @"Root View";   
  6.     self.navController = [[UINavigationController alloc] init];   
  7.     [self.navController pushViewController:rootView animated:YES];   
  8.     [self.window addSubview:self.navController.view];   
  9.     [self.window makeKeyAndVisible];   
  10.     return YES;   
  11. }   

給rootView的titie命名為 Root View,好識別View直接的切換關系。用pushViewController把rootView加入到navController的視圖棧中。

7、現在Root視圖添加完成

看看效果:

現在還沒有Navigation bar 。只有title。

8、添加UIBarButtonItem

bar ButtonItem分左右UIBarButtonItem。我們把左右的都添加上去。

在RootViewController.m中添加代碼如下:

  1. - (void)viewDidLoad   
  2. {   
  3.     [super viewDidLoad];   
  4.     UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectLeftAction:)];   
  5.     self.navigationItem.leftBarButtonItem = leftButton;   
  6.     UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd  target:self action:@selector(selectRightAction:)];   
  7.     self.navigationItem.rightBarButtonItem = rightButton;<p class="p1">}</p>   

這樣添加了UIBarButtonItem了,效果如下:

這里重點介紹下

UIBarButtonItem *leftButton = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemActiontarget:selfaction:@selector(selectLeftAction:)];

UIBarButtonSystemItemAction的風格,這是系統自帶的按鈕風格,看下圖,你不用一個個試驗,你也知道想用那個item,如下圖:

9、響應UIBarButtonItem的事件的實現

我們在 action:@selector(selectLeftAction:);

action添加了selectLeftAction和selectRightAction

在RootViewController.m文件中添加代碼實現:

  1. -(void)selectLeftAction:(id)sender   
  2. {   
  3.     UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你點擊了導航欄左按鈕" delegate:self  cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];   
  4.     [alter show];   
  5. }   
  6. -(void)selectRightAction:(id)sender   
  7. {   
  8.     UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你點擊了導航欄右按鈕" delegate:self  cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];   
  9.     [alter show];   

這樣在點擊左右的UIBarButtonItem時,彈出提示:

這篇先講添加UIBarButtonItem,下篇講解頁面跳轉和添加UISegmentedControl

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

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

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

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

2013-04-02 10:16:34

iOS學習UINavigatio頁面切換

2013-04-02 10:36:43

iOS學習UINavigatioToolBar

2011-08-02 11:07:42

iOS開發 UIWebView

2011-07-26 17:31:52

iOS 設計模式

2015-07-09 13:47:37

IOSFMDB

2011-08-23 13:56:12

MySQLConnection

2019-01-04 15:14:18

2011-08-16 14:59:31

IOS開發ViewDidUnloiOS 5

2019-02-12 15:04:09

2011-08-16 15:35:50

MySQLSELECT語句FROM子句

2011-08-03 17:32:17

IOS UIScrollVi touch

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-07-18 14:39:53

iPhone SDK UIKit

2022-12-22 07:40:28

2013-01-30 15:36:03

NFC移動支付藍牙

2010-07-06 10:56:32

UML圖詳解

2012-05-10 08:55:11

Linuxuniq

2023-09-27 09:18:35

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 午夜精品一区 | 99精品国产一区二区三区 | 九九热精品视频 | 欧洲亚洲精品久久久久 | 国产精品大片在线观看 | 久久综合久色欧美综合狠狠 | 武道仙尊动漫在线观看 | 午夜影视 | 中文字幕在线观看国产 | 欧美1区 | 人人人人干 | 9色视频在线 | 中国美女撒尿txxxxx视频 | 成人免费大片黄在线播放 | 久久国产精品亚洲 | 欧美精品一区二区三区在线四季 | 中文字幕一区二区三区四区五区 | 欧美一级在线观看 | 亚洲视频一区在线观看 | 91精品久久久久久久久中文字幕 | 亚洲国产欧美一区二区三区久久 | 久久国产精品视频免费看 | 成人免费在线视频 | 亚洲精品日韩在线 | 国产精品亚洲综合 | 美女天天干 | av一二三区| 夜夜精品浪潮av一区二区三区 | 老司机精品福利视频 | 欧美久久一区二区三区 | 欧美一区二区久久 | 国产精品视频一二三区 | 免费视频99| 久久精品国产99国产 | 不卡一区二区三区四区 | 一区精品视频在线观看 | 香蕉av免费 | 91在线看| 欧美一级免费观看 | 日本在线视频一区二区 | 久久久久久久电影 |