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