zoukankan      html  css  js  c++  java
  • block

    反向传值

    第二个类中:

    @interface NationNumberViewController : BaseViewController

    @property (nonatomic, strong)void (^selectBlock)(NSString *num);

    @end

    #pragma mark ------- tableViewDelegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        if (_selectBlock) {

            _selectBlock([_tableViewDatasource[indexPath.section] objectForKey:@"data"][indexPath.row][2]);

        }

        [self.navigationController popViewControllerAnimated:YES];

    }

     第一个类中:

    -(void)arrowBtnClick:(NationBtn *)button

    {

        NationNumberViewController * nationVC=[[NationNumberViewController alloc]init];

        nationVC.selectBlock=^(NSString *num){

            [button setTitle:num forState:UIControlStateNormal];

        };

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

    }

     赋值

      NationBtn * nationBtn=[[NationBtn alloc]initWithFrame:CGRectMake(15, 0, 80, 44)];

        if (nationBtn.titleLabel.text.length==0) {

            [nationBtn setTitle:@"+86" forState:UIControlStateNormal];

        }

            __block NationBtn *myTell = nationBtn;

            _nation.selectBlock = ^(NSString *num){

                // 在这里设置 下面TextField 区号就好了

                [myTell setTitle:num forState:UIControlStateNormal];

            };

        [nationBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [nationBtn setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal];

        [nationBtn addTarget:self action:@selector(arrowBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        [registerBg addSubview:nationBtn];

        

  • 相关阅读:
    layui穿梭框右侧增加上移下移功能
    java.lang.NullPointerException出现的几种原因:
    springboot+thymeleaf+mybatis 基础学习
    Vue 生命周期扫盲
    Token 认证(Asp.Net)
    从具体化“system.decimal”类型到“system.string”类型的指定强制转换无效
    【C#】委托和Lambda表达式
    Visual Studio 2017添加visionPro控件
    从WinForm程序中看委托和事件
    西门子PLC通讯-仿真环境搭建
  • 原文地址:https://www.cnblogs.com/momosmile/p/5287555.html
Copyright © 2011-2022 走看看