zoukankan      html  css  js  c++  java
  • iOS block进行页面之间传值

    #import <UIKit/UIKit.h>

    @interface FirstViewController : UIViewController

    @property (weak, nonatomic) IBOutlet UITextField *contentTxtField;

    @end

    #import "SecondViewController.h"

    #import "FirstViewController.h"

    @interface FirstViewController ()

    @end

    @implementation FirstViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

    }

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    - (IBAction)jumpToSecondBtnClick:(UIButton *)sender

    {

        UIStoryboard *firstSb=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

        SecondViewController *secondCtl=[firstSb instantiateViewControllerWithIdentifier:@"second"];

        [secondCtl compeleteBlock:^(NSString *string) {

            

            _contentTxtField.text=string;

            

        }];

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

        

        

    }

    @end

    #import <UIKit/UIKit.h>

    typedef void (^BlockPassValue) (NSString *string);

    @interface SecondViewController : UIViewController

    {

        BlockPassValue myBlockValue;

    }

    @property (weak, nonatomic) IBOutlet UITextField *valueTxtField;

    -(void)compeleteBlock:(BlockPassValue)myblock;

    @end

    #import "SecondViewController.h"

    @interface SecondViewController ()

    @end

    @implementation SecondViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

    }

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    -(void)compeleteBlock:(BlockPassValue)myblock

    {

        myBlockValue=myblock;

    }

    - (IBAction)backToFirstBtnClick:(UIButton *)sender

    {

        

        if (myBlockValue)

        {

            myBlockValue(_valueTxtField.text);

        }

        [self.navigationController popViewControllerAnimated:YES];

    }

    @end

     

  • 相关阅读:
    多个手机号逗号分开
    字符转码
    短信发送AZDG加密算法
    判断手机所属三大运营商 移动、联通、电信
    MD5加密 时间差 流水号等方法
    VS2012的创建单元测试功能
    Oracle数据库操作类及连接方法
    python生成器,函数,数组
    javascript的单线程
    linux下/var/run目录下.pid文件的作用
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4089458.html
Copyright © 2011-2022 走看看