反向傳值ide
第二個類中:atom
@interface NationNumberViewController : BaseViewControllerorm
@property (nonatomic, strong)void (^selectBlock)(NSString *num);get
@endit
#pragma mark ------- tableViewDelegateio
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathtable
{object
if (_selectBlock) {select
_selectBlock([_tableViewDatasource[indexPath.section] objectForKey:@"data"][indexPath.row][2]);im
}
[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];