UI 07 _ 导航视图控制器 与 属性传值
生活随笔
收集整理的這篇文章主要介紹了
UI 07 _ 导航视图控制器 与 属性传值
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先, 先創(chuàng)建三個VC.
完畢點擊按鈕, 進入下一頁, 并可以返回.
要先把導(dǎo)航視圖控制器創(chuàng)建出來.
在AppDelegate.m 文件里代碼例如以下:
對于導(dǎo)航視圖控制器的一些設(shè)置.
//導(dǎo)航視圖控制器的高度是44,上面的狀態(tài)欄高度是20,加在一起默認是64;// 加上一個標題.self.title = @"貓眼電影";// 對外觀進行設(shè)置,不是全部的顏色都是BackgroundColor;self.navigationController.navigationBar.barTintColor = [UIColor redColor]; // 創(chuàng)建一個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;內(nèi)容方面的設(shè)置
//另外一種標題的設(shè)置self.navigationItem.title = @"骨頭 商店";// 指定一些視圖,作為titleViewUISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息",@"通話"]];self.navigationItem.titleView = seg;[seg release];創(chuàng)建左右兩個按鈕
//左按鈕self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemOrganize target:self action:@selector(leftAction:)] autorelease];//右按鈕//如此創(chuàng)建,原本拖拽的圖標的顏色是黃色,但這么創(chuàng)建后,圖標是藍色的.self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"狗.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease];// 以下方法圖標將會顯示黃色.// 創(chuàng)建一個小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];對應(yīng)的, 左右兩個按鈕的點擊事件也要實現(xiàn)
- (void)rightAction:(UIBarButtonItem *)button{ }- (void)leftAction:(UIBarButtonItem *)barButton{ }點擊Button跳轉(zhuǎn)到下一頁.
用模態(tài)也可以跳轉(zhuǎn) , 可是跳轉(zhuǎn)的頁面不再有導(dǎo)航視圖.
實現(xiàn)Button的點擊事件
當(dāng)中我要完畢從前向后傳值.
第二個頁面的 .h 中代碼:
#import <UIKit/UIKit.h>@interface SecondViewController : UIViewController // 屬性傳值第一步,在第二個頁面寫一條屬性. @property(nonatomic, assign)NSInteger number;//屬性傳值另外一種: 針對TextField中的字符串寫一條屬性. @property(nonatomic, copy)NSString *string;//屬性傳值第三種: 傳一個數(shù)組 @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
轉(zhuǎn)載于:https://www.cnblogs.com/brucemengbm/p/7202073.html
總結(jié)
以上是生活随笔為你收集整理的UI 07 _ 导航视图控制器 与 属性传值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器学习笔记——深度学习入门篇
- 下一篇: 利用Maven快速创建一个简单的spri