導航欄/界面傳值

self.view.backgroundColor = [UIColor redColor];

// 導航欄設置: controller(欄)/item(欄上的元素)

// 導航欄顯示/隱藏

self.navigationController.navigationBarHidden = NO;

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

// 欄樣式

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

// 半透明效果

// 開始效果時 屏幕左上角為坐標原點

// 關閉時 導航欄的左下角為坐標原點

self.navigationController.navigationBar.translucent = YES;

// 創建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];

// 欄標題

self.title = @"這是一個標題";

// ? ?self.navigationItem.title = @"這是一個猴賽雷的標題";

// 分段

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

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

// 欄標題視圖

self.navigationItem.titleView = seg;

// 欄左側按鈕

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

// 欄右側按鈕

// 系統按鈕樣式

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

// 修改導航欄上內容的顏色

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

// 跳轉頁面

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 - 跳轉頁面

- (void)goTwo

{

// 1.獲取第二頁對象

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

// 2.跳轉(由導航控制器 從當前push到第二頁)

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

// 3.內存管理

[twoVC release];

}

- (void)right1

{

NSLog(@"右1");

}

- (void)right2

{

NSLog(@"右2");

}

#pragma mark - 左按鈕觸發方法

- (void)left:(UIBarButtonItem *)left

{

NSLog(@"左點點");

}


界面間 傳值

#import"RootViewController.h"

#import"TwoViewController.h"

#warning協議4:簽協議

@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=@"首頁";

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頁面之前傳值(創建對象之后push之前)

two.string=self.table.text;

#warning協議5:設置代理人

//為了保證設置代理人的對象和設置push對象是同一個在創建對象之后push之前設置delegate

two.delegate=self;

[self.navigationControllerpushViewController:twoanimated:YES];

[tworelease];

}

#warning協議6:實現協議方法

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

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

self.table.text= string;

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

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

//

// ?TwoViewController.h

#import

#warning協議1:聲明協議(定義一個帶參數的方法)

@protocolPassDelegate

//必須要實現的@required(默認)

//@optional可選的

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

@end

@interfaceTwoViewController :UIViewController

#warning屬性1:在第二頁聲明一個屬性用來保存數據

@property(nonatomic,copy)NSString*string;

#warning協議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=@"第二頁";

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:通過屬性給當前頁面賦值

self.table2.text=self.string;

}

-(void)goBack{

#warning協議3:返回上一頁之前代理人調用協議方法

[self.delegatepassValue:self.table2.text];//self.delegate相當于rootVC頁面執行pass方法

[self.navigationControllerpopToRootViewControllerAnimated:YES];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • //準備工作 1.刪除Main 2.ARC->MRC(YES->No) 3.刪除文件(ViewConTroller...
    愛吃芒果的淼小豬閱讀 404評論 1 1
  • VC中 自帶一個view 用于鋪設視圖 默認顏色為透明 self.view.backgroundColor = [...
    青花_閱讀 287評論 0 0
  • 1.不可變數組轉變為可變數組聲明實例變量的數組 必須記得實現 對于遍歷數組找到對象后 如果還需要查找 記得先結束 ...
    小新xin閱讀 754評論 0 1
  • 用cocoaPods配置第三方文件 第一步。打開終端 第二步。cd+文件夾 第三步。pod init 第四步。打開...
    不說謊的匹諾曹Y閱讀 1,121評論 0 1
  • 我幾乎是全程以悲傷的情緒看完《悟空傳》的,因為我從一開始就認定了孫悟空不會成功,我似乎可以贊同了為什么會有人說此劇...
    9e5a65fc4721閱讀 197評論 0 0