IOS 學習筆記 2015-04-15 控制器資料反向傳值,ios2015-04-15

來源:互聯網
上載者:User

IOS 學習筆記 2015-04-15 控制器資料反向傳值,ios2015-04-15

////  FirstViewController.h//  控制器資料傳遞////  Created by wangtouwang on 15/4/15.//  Copyright (c) 2015年 wangtouwang. All rights reserved.//#import <UIKit/UIKit.h>@interface FirstViewController : UIViewController@end////  FirstViewController.m//  控制器資料傳遞////  Created by wangtouwang on 15/4/15.//  Copyright (c) 2015年 wangtouwang. All rights reserved.//#import "FirstViewController.h"#import "TwoViewController.h"@interface FirstViewController ()<PropagateDelegate>{    UILabel *firstLable;    UITextField *firstField;    UIButton *firstBtn;}@end@implementation FirstViewController- (void)viewDidLoad {    [super viewDidLoad];    [self.view setBackgroundColor:[UIColor blackColor]];        firstLable = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 150, 30)];    firstLable.text=@"第一頁面進出值";    firstLable.font=[UIFont systemFontOfSize:15.0];    firstLable.textColor=[UIColor whiteColor];     [self.view addSubview:firstLable];        firstField = [[UITextField alloc] initWithFrame:CGRectMake(30, 150, 150, 30)];    firstField.textColor=[UIColor blackColor];    firstField.font=[UIFont fontWithName:@"Arial" size:14.0];    firstField.borderStyle=UITextBorderStyleRoundedRect;    firstField.placeholder = @"進出值";    firstField.keyboardType = UIKeyboardTypeDefault;     [self.view addSubview:firstField];        firstBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 210, 150, 30)];    firstBtn.backgroundColor=[UIColor colorWithRed:195/255.0 green:33/255.0 blue:30/255.0 alpha:1.0];    [firstBtn setTitle:@"跳轉第二頁面" forState:UIControlStateNormal];    [firstBtn.layer setCornerRadius:10.0]; //設定矩形四個圓角半徑    [firstBtn addTarget:self action:@selector(turnTwoPage:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:firstBtn];    }-(void)turnTwoPage:(UIButton *)btn{    TwoViewController *two = [[TwoViewController alloc] init];    two.delegate=self;    [self.navigationController pushViewController:two animated:NO];}-(void)propagateToValue:(NSString *)result{    NSLog(@"反向傳值");    firstField.text=result;}@end
////  TwoViewController.h//  控制器資料傳遞////  Created by wangtouwang on 15/4/15.//  Copyright (c) 2015年 wangtouwang. All rights reserved.//#import <UIKit/UIKit.h>@protocol PropagateDelegate <NSObject>@required-(void)propagateToValue:(NSString *)result;@end@interface TwoViewController : UIViewController@property(nonatomic,assign) id<PropagateDelegate> delegate;@end
////  TwoViewController.m//  控制器資料傳遞////  Created by wangtouwang on 15/4/15.//  Copyright (c) 2015年 wangtouwang. All rights reserved.//#import "TwoViewController.h"@interface TwoViewController ()@property(nonatomic,strong) UILabel *firstLable;@property(nonatomic,strong) UITextField *firstField;@property(nonatomic,strong) UIButton *firstBtn;@end@implementation TwoViewController- (void)viewDidLoad {    [super viewDidLoad];    [self.view setBackgroundColor:[UIColor blackColor]];        _firstLable = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 150, 30)];    _firstLable.text=@"第二頁面進出值";    _firstLable.font=[UIFont systemFontOfSize:15.0];    _firstLable.textColor=[UIColor whiteColor];    [self.view addSubview:_firstLable];        _firstField = [[UITextField alloc] initWithFrame:CGRectMake(30, 150, 150, 30)];    _firstField.textColor=[UIColor blackColor];    _firstField.font=[UIFont fontWithName:@"Arial" size:14.0];    _firstField.borderStyle=UITextBorderStyleRoundedRect;    _firstField.placeholder = @"進出值";    _firstField.keyboardType = UIKeyboardTypeDefault;    [self.view addSubview:_firstField];        _firstBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 210, 150, 30)];    _firstBtn.backgroundColor=[UIColor colorWithRed:195/255.0 green:33/255.0 blue:30/255.0 alpha:1.0];    [_firstBtn setTitle:@"跳轉第一頁面" forState:UIControlStateNormal];    [_firstBtn.layer setCornerRadius:10.0]; //設定矩形四個圓角半徑    [_firstBtn addTarget:self action:@selector(turnFirstPage:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:_firstBtn];}//反向傳值-(void)turnFirstPage:(UIButton *)btn{    [self.delegate propagateToValue:_firstField.text];    [self.navigationController popViewControllerAnimated:NO];}@end

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.