zoukankan      html  css  js  c++  java
  • IOS 学习笔记 2015-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
  • 相关阅读:
    RAW和JPEG的区别_ZT
    用户自定义基元UDP_ZT
    UDP用户自定义原语
    SR锁存器
    Matlab实现Butterworth滤波器 分类: 图像处理 2014-06-02 00:05 527人阅读 评论(0) 收藏
    egrep命令的实现 分类: 编译原理 2014-06-01 23:41 329人阅读 评论(0) 收藏
    随机L系统分形树 分类: 计算机图形学 2014-06-01 23:27 376人阅读 评论(0) 收藏
    matlab实现算术编解码 分类: 图像处理 2014-06-01 23:01 357人阅读 评论(0) 收藏
    命名管道实现进程间通信--石头、剪刀、布游戏 分类: linux 2014-06-01 22:50 467人阅读 评论(0) 收藏
    互斥锁与条件变量应用 2014-06-01 22:20 328人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/ak23173969/p/4428922.html
Copyright © 2011-2022 走看看