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];
}