zoukankan      html  css  js  c++  java
  • Block传值原理

    #import <UIKit/UIKit.h>

    #import "SecondViewController.h"

    @interface ViewController : UIViewController<UITextFieldDelegate>

    @property (nonatomic ,strong) UITextField *textName;

    @property (nonatomic ,strong) UIButton *button;

    @end

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"5622630220130817130527093.jpg"]];

        self.textName = [[UITextField alloc ] initWithFrame:CGRectMake(100, 100, 100, 50)];

        self.textName.backgroundColor = [UIColor grayColor];

        self.textName.textColor = [UIColor greenColor];

        self.textName.delegate = self;

        [self.view addSubview:self.textName];

        self.button = [[UIButton alloc] initWithFrame:CGRectMake(120, 160, 80, 40)];

        [self.button setTitle:@"下一页" forState:UIControlStateNormal];

        [self.button addTarget:self action:@selector(nextPage) forControlEvents: UIControlEventTouchUpInside ];

        [self.view addSubview:self.button];

        

    }

    -(BOOL)textFieldShouldReturn:(UITextField *)textField{

        if ([self.textName isFirstResponder]) {

            [self.textName resignFirstResponder];

        }

        return YES;

    }

    -(void)nextPage

    {

        SecondViewController *second =  [[SecondViewController alloc] init];

        second.str = self.textName.text;

        second.postvalueb = ^(NSString *str){

            self.textName.text = str;

            NSLog(@"%@",str);

        };

        [self presentViewController:second animated:YES completion:^{

            NSLog(@"页面跳转成功");

        }];

        

        

    }

    #import <UIKit/UIKit.h>

    typedef void(^postValueBlock)(NSString *);

    @interface SecondViewController : UIViewController<UITextFieldDelegate>

    @property (nonatomic ,strong) NSString *str;

    @property (nonatomic ,strong) postValueBlock postvalueb;

    @property (nonatomic ,strong)  UITextField *textFil;

    @end

    @implementation SecondViewController

    - (void)viewDidLoad {

        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"5622630220130817130527093.jpg"]];

        self.textFil = [[UITextField alloc ] initWithFrame:CGRectMake(100, 100, 100, 50)];

        self.textFil.backgroundColor = [UIColor grayColor];

        self.textFil.textColor = [UIColor greenColor];

        //属性传值

        self.textFil.text = self.str;

        self.textFil.delegate = self;

        [self.view addSubview:self.textFil];

        

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    -(BOOL)textFieldShouldReturn:(UITextField *)textField

    {

        if(self.postvalueb){

                   self.postvalueb(self.textFil.text);

            

        }

        if ([self.textFil isFirstResponder]) {

            [self.textFil resignFirstResponder];

        }

        [self dismissViewControllerAnimated:YES completion:nil];

        

        return YES;

    }

    @end

  • 相关阅读:
    INFO: InstallShield不同版本对中文字符串的支持程度
    Basic INFO: InstallShield 2012安装过程
    [Android] 打印Log的行号、函数、类名
    gridgian 网格计算
    Activity及Dialog的全透明
    设计工具
    ps 多图层扣图
    spket js ide
    a 的样式
    js开发规范
  • 原文地址:https://www.cnblogs.com/liumu/p/5281621.html
Copyright © 2011-2022 走看看