日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UI 07 _ 导航视图控制器 与 属性传值

發布時間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UI 07 _ 导航视图控制器 与 属性传值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先, 先創建三個VC.
完畢點擊按鈕, 進入下一頁, 并可以返回.

要先把導航視圖控制器創建出來.
在AppDelegate.m 文件里代碼例如以下:

#import "AppDelegate.h" #import "MainViewController.h" @interface AppDelegate () @end@implementation AppDelegate - (void)dealloc{[_window release];[super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Override point for customization after application launch.self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];[_window release];//先創建一個ViewControllerMainViewController *mainVC = [[MainViewController alloc] init];//創建導航視圖控制器UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:mainVC];self.window.rootViewController = navC;//釋放[mainVC release];[navC release];return YES; }

對于導航視圖控制器的一些設置.

//導航視圖控制器的高度是44,上面的狀態欄高度是20,加在一起默認是64;// 加上一個標題.self.title = @"貓眼電影";// 對外觀進行設置,不是全部的顏色都是BackgroundColor;self.navigationController.navigationBar.barTintColor = [UIColor redColor]; // 創建一個UIViewUIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];view.backgroundColor = [UIColor orangeColor];[self.view addSubview:view];[view release];// 為了防止坐標系被篡改,我們把bar從半透明改為全透明.這樣坐標系的原點會自己主動向下推64self.navigationController.navigationBar.translucent = NO;

內容方面的設置

//另外一種標題的設置self.navigationItem.title = @"骨頭 商店";// 指定一些視圖,作為titleViewUISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息",@"通話"]];self.navigationItem.titleView = seg;[seg release];

創建左右兩個按鈕

//左按鈕self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemOrganize target:self action:@selector(leftAction:)] autorelease];//右按鈕//如此創建,原本拖拽的圖標的顏色是黃色,但這么創建后,圖標是藍色的.self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"狗.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];// 以下方法圖標將會顯示黃色.// 創建一個小button,把圖片裝上.UIButton *Littlebutton = [UIButton buttonWithType:UIButtonTypeCustom];Littlebutton.frame = CGRectMake(0, 0, 40, 40);[Littlebutton setImage:[UIImage imageNamed:@"狗.png"] forState:UIControlStateNormal];self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Littlebutton];UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(260, 530, 80, 40);button.backgroundColor = [UIColor yellowColor];[self.view addSubview:button];[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];button.layer.cornerRadius = 10;[button setTitle:@"下一頁" forState:UIControlStateNormal];

對應的, 左右兩個按鈕的點擊事件也要實現

- (void)rightAction:(UIBarButtonItem *)button{ }- (void)leftAction:(UIBarButtonItem *)barButton{ }

點擊Button跳轉到下一頁.
用模態也可以跳轉 , 可是跳轉的頁面不再有導航視圖.
實現Button的點擊事件
當中我要完畢從前向后傳值.

- (void)click:(UIButton *)button{ - // 用導航視圖控制器跳轉.//1.先創建下一頁對象.SecondViewController *secondVC = [[SecondViewController alloc] init];//通過導航控制器找到[self.navigationController pushViewController:secondVC animated:YES];[secondVC release];// 屬性傳值第二步secondVC.number = 100;secondVC.string = self.textField.text;secondVC.arr = @[@"haha",@"啦啦"]; }

第二個頁面的 .h 中代碼:

#import <UIKit/UIKit.h>@interface SecondViewController : UIViewController // 屬性傳值第一步,在第二個頁面寫一條屬性. @property(nonatomic, assign)NSInteger number;//屬性傳值另外一種: 針對TextField中的字符串寫一條屬性. @property(nonatomic, copy)NSString *string;//屬性傳值第三種: 傳一個數組 @property(nonatomic, retain)NSArray *arr;@end

第二個頁面的 .m 中代碼:

#import "SecondViewController.h" #import "ThirdViewController.h" @interface SecondViewController () @property(nonatomic, retain)UILabel *label; @end@implementation SecondViewController - (void)dealloc{[_label release];[_string release];[_arr release];[super dealloc]; }- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.view.backgroundColor = [UIColor yellowColor];self.navigationController.navigationBar.barTintColor = [UIColor magentaColor];UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];button.frame = CGRectMake(260, 530, 80, 40);button.backgroundColor = [UIColor blueColor];[self.view addSubview:button];[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];button.layer.cornerRadius = 10;[button setTitle:@"下一頁" forState:UIControlStateNormal];//第三步://第一種:NSLog(@"%ld",self.number);//另外一種:self.label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];[self.view addSubview:self.label];[_label release];self.label.layer.borderWidth = 1;//屬性傳值第三步:里面的值賦給labelself.label.text = self.string;// 第三種:NSLog(@"%@",self.arr[1]); } - (void)click:(UIButton *)button{ThirdViewController *thirdVC = [[ThirdViewController alloc] init];[self.navigationController pushViewController:thirdVC animated:YES];[thirdVC release]; }

屬性傳值. 傳NSIntger . NSString . NSArray

轉載于:https://www.cnblogs.com/brucemengbm/p/7202073.html

總結

以上是生活随笔為你收集整理的UI 07 _ 导航视图控制器 与 属性传值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。