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];

        

  • 相关阅读:
    etcd客户端c#
    【Python 2 到 3 系列】 关于除法的余数
    彻底搞定C指针--“函数名与函数指针”
    关于 函数指针和函数名 例子的疑难解答
    stat.h头文件,轻松获取文件属性
    C++指针之间的赋值与转换规则总结
    (转)mblog解读(二)
    (转)mblog解读(一)
    (转)renren-fast解读(二)
    (转)renren-fast解读(一)
  • 原文地址:https://www.cnblogs.com/momosmile/p/5287555.html
Copyright © 2011-2022 走看看