導(dǎo)航欄/界面?zhèn)髦?/h1>

self.view.backgroundColor = [UIColor redColor];

// 導(dǎo)航欄設(shè)置: controller(欄)/item(欄上的元素)

// 導(dǎo)航欄顯示/隱藏

self.navigationController.navigationBarHidden = NO;

// ? ?self.navigationController.navigationBar.hidden = YES;

// 欄樣式

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

// 半透明效果

// 開始效果時(shí) 屏幕左上角為坐標(biāo)原點(diǎn)

// 關(guān)閉時(shí) 導(dǎo)航欄的左下角為坐標(biāo)原點(diǎn)

self.navigationController.navigationBar.translucent = YES;

// 創(chuàng)建view(0,0,100,100)

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

view.backgroundColor = [UIColor greenColor];

[self.view addSubview:view];

[view release];

// 欄背景顏色

self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];

// 欄顏色

self.navigationController.navigationBar.barTintColor = [UIColor grayColor];

// 欄標(biāo)題

self.title = @"這是一個(gè)標(biāo)題";

// ? ?self.navigationItem.title = @"這是一個(gè)猴賽雷的標(biāo)題";

// 分段

UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:@[@"消息", @"電話"]] autorelease];

seg.frame = CGRectMake(0, 0, 100, 30);

// 欄標(biāo)題視圖

self.navigationItem.titleView = seg;

// 欄左側(cè)按鈕

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(left:)] autorelease];

// 欄右側(cè)按鈕

// 系統(tǒng)按鈕樣式

UIBarButtonItem *b1 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(right1)] autorelease];

// 自定義按鈕圖片

UIBarButtonItem *b2 = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"dianzan"] style:UIBarButtonItemStylePlain target:self action:@selector(right2)] autorelease];

self.navigationItem.rightBarButtonItems = @[b1, b2];

// 修改導(dǎo)航欄上內(nèi)容的顏色

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

// 跳轉(zhuǎn)頁(yè)面

UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];

btn.frame = CGRectMake(200, 200, 100, 100);

btn.backgroundColor = [UIColor yellowColor];

[self.view addSubview:btn];

[btn addTarget:self action:@selector(goTwo) forControlEvents:UIControlEventTouchUpInside];

}

#pragma mark - 跳轉(zhuǎn)頁(yè)面

- (void)goTwo

{

// 1.獲取第二頁(yè)對(duì)象

TwoViewController *twoVC = [[TwoViewController alloc] init];

// 2.跳轉(zhuǎn)(由導(dǎo)航控制器 從當(dāng)前push到第二頁(yè))

[self.navigationController pushViewController:twoVC animated:YES];

// 3.內(nèi)存管理

[twoVC release];

}

- (void)right1

{

NSLog(@"右1");

}

- (void)right2

{

NSLog(@"右2");

}

#pragma mark - 左按鈕觸發(fā)方法

- (void)left:(UIBarButtonItem *)left

{

NSLog(@"左點(diǎn)點(diǎn)");

}


界面間 傳值

#import"RootViewController.h"

#import"TwoViewController.h"

#warning協(xié)議4:簽協(xié)議

@interfaceRootViewController ()

@property(nonatomic,retain)UITextField*table;

@end

@implementationRootViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor= [UIColorwhiteColor];

self.navigationController.navigationBarHidden=NO;

self.navigationController.navigationBar.translucent=NO;

// self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

self.title=@"首頁(yè)";

self.table= [[UITextFieldalloc]initWithFrame:CGRectMake(60,30,260,40)];

self.table.backgroundColor= [UIColorwhiteColor];

[self.viewaddSubview:self.table];

[self.tablerelease];

self.table.layer.borderColor= [UIColorlightGrayColor].CGColor;

self.table.layer.borderWidth=1;

self.table.layer.cornerRadius=5;

UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeSystem];

btn.frame=CGRectMake(60,120,260,40);

btn.backgroundColor= [UIColorredColor];

[self.viewaddSubview:btn];

[btn addTarget:selfaction:@selector(goFor) forControlEvents:UIControlEventTouchUpInside];

}

-(void)goFor{

TwoViewController*two = [[TwoViewControlleralloc]init];

#warning屬性2:在push頁(yè)面之前傳值(創(chuàng)建對(duì)象之后push之前)

two.string=self.table.text;

#warning協(xié)議5:設(shè)置代理人

//為了保證設(shè)置代理人的對(duì)象和設(shè)置push對(duì)象是同一個(gè)在創(chuàng)建對(duì)象之后push之前設(shè)置delegate

two.delegate=self;

[self.navigationControllerpushViewController:twoanimated:YES];

[tworelease];

}

#warning協(xié)議6:實(shí)現(xiàn)協(xié)議方法

-(void)passValue:(NSString*)string{

//把收到的string賦值給輸入框

self.table.text= string;

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

*******************************************************************************

//

// ?TwoViewController.h

#import

#warning協(xié)議1:聲明協(xié)議(定義一個(gè)帶參數(shù)的方法)

@protocolPassDelegate

//必須要實(shí)現(xiàn)的@required(默認(rèn))

//@optional可選的

-(void)passValue:(NSString*)string;//需要傳什么數(shù)據(jù)就設(shè)置什么屬性

@end

@interfaceTwoViewController :UIViewController

#warning屬性1:在第二頁(yè)聲明一個(gè)屬性用來保存數(shù)據(jù)

@property(nonatomic,copy)NSString*string;

#warning協(xié)議2:定義代理人屬性

@property(nonatomic,assign)iddelegate;

@end

*********************************************

TwoViewController.m

#import"TwoViewController.h"

@interfaceTwoViewController()

@property(nonatomic,retain)UITextField*table2;

@end

@implementationTwoViewController

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor= [UIColorwhiteColor];

self.title=@"第二頁(yè)";

self.table2= [[UITextFieldalloc]initWithFrame:CGRectMake(60,30,260,40)];

self.table2.backgroundColor= [UIColorwhiteColor];

[self.viewaddSubview:self.table2];

[self.table2release];

self.table2.layer.borderColor= [UIColorlightGrayColor].CGColor;

self.table2.layer.borderWidth=1;

self.table2.layer.cornerRadius=5;

UIButton*btn = [UIButtonbuttonWithType:UIButtonTypeSystem];

btn.frame=CGRectMake(60,120,260,40);

btn.backgroundColor= [UIColorredColor];

[self.viewaddSubview:btn];

[btnaddTarget:selfaction:@selector(goBack)forControlEvents:UIControlEventTouchUpInside];

#warning屬性3:通過屬性給當(dāng)前頁(yè)面賦值

self.table2.text=self.string;

}

-(void)goBack{

#warning協(xié)議3:返回上一頁(yè)之前代理人調(diào)用協(xié)議方法

[self.delegatepassValue:self.table2.text];//self.delegate相當(dāng)于rootVC頁(yè)面執(zhí)行pass方法

[self.navigationControllerpopToRootViewControllerAnimated:YES];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者

  • 序言:七十年代末瞧柔,一起剝皮案震驚了整個(gè)濱河市吧凉,隨后出現(xiàn)的幾起案子济竹,更是在濱河造成了極大的恐慌褐奥,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,755評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異馋劈,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)晾嘶,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門妓雾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人变擒,你說我怎么就攤上這事君珠。” “怎么了娇斑?”我有些...
    開封第一講書人閱讀 165,138評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵策添,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我毫缆,道長(zhǎng)唯竹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,791評(píng)論 1 295
  • 正文 為了忘掉前任苦丁,我火速辦了婚禮浸颓,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己产上,他們只是感情好棵磷,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著晋涣,像睡著了一般仪媒。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上谢鹊,一...
    開封第一講書人閱讀 51,631評(píng)論 1 305
  • 那天算吩,我揣著相機(jī)與錄音,去河邊找鬼佃扼。 笑死偎巢,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的兼耀。 我是一名探鬼主播压昼,決...
    沈念sama閱讀 40,362評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼翠订!你這毒婦竟也來了巢音?” 一聲冷哼從身側(cè)響起遵倦,我...
    開封第一講書人閱讀 39,264評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤尽超,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后梧躺,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體似谁,經(jīng)...
    沈念sama閱讀 45,724評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年掠哥,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了巩踏。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,040評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡续搀,死狀恐怖塞琼,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情禁舷,我是刑警寧澤彪杉,帶...
    沈念sama閱讀 35,742評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站牵咙,受9級(jí)特大地震影響派近,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜洁桌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評(píng)論 3 330
  • 文/蒙蒙 一渴丸、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦谱轨、人聲如沸戒幔。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)溪食。三九已至,卻和暖如春娜扇,著一層夾襖步出監(jiān)牢的瞬間错沃,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工雀瓢, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留枢析,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,247評(píng)論 3 371
  • 正文 我出身青樓刃麸,卻偏偏與公主長(zhǎng)得像醒叁,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子泊业,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • //準(zhǔn)備工作 1.刪除Main 2.ARC->MRC(YES->No) 3.刪除文件(ViewConTroller...
    愛吃芒果的淼小豬閱讀 391評(píng)論 1 1
  • VC中 自帶一個(gè)view 用于鋪設(shè)視圖 默認(rèn)顏色為透明 self.view.backgroundColor = [...
    青花_閱讀 267評(píng)論 0 0
  • 1.不可變數(shù)組轉(zhuǎn)變?yōu)榭勺償?shù)組聲明實(shí)例變量的數(shù)組 必須記得實(shí)現(xiàn) 對(duì)于遍歷數(shù)組找到對(duì)象后 如果還需要查找 記得先結(jié)束 ...
    小新xin閱讀 703評(píng)論 0 1
  • 用cocoaPods配置第三方文件 第一步把沼。打開終端 第二步。cd+文件夾 第三步吁伺。pod init 第四步饮睬。打開...
    不說謊的匹諾曹Y閱讀 1,084評(píng)論 0 1
  • 我?guī)缀跏侨桃员瘋那榫w看完《悟空傳》的,因?yàn)槲覐囊婚_始就認(rèn)定了孫悟空不會(huì)成功篮奄,我似乎可以贊同了為什么會(huì)有人說此劇...
    9e5a65fc4721閱讀 182評(píng)論 0 0