您的位置:首页 > 移动开发 > IOS开发

iOS每日一记之——————点击按钮进入到国家选择列表并回调

2015-10-15 10:53 495 查看
1.

// 初始化手机号国家前缀按钮

self.countryCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(24, 5, 58, 40)];

[self.countryCodeBtn addTarget:self action:@selector(selectCountryCode) forControlEvents:UIControlEventTouchUpInside];

[whiteView addSubview:self.countryCodeBtn];

2.实现selectCountryCode方法

- (void)selectCountryCode {

__weak typeof(self) weakSelf = self;

SelectCountryCodeViewController *selectCountryCodeViewController = [[SelectCountryCodeViewController alloc] init];

selectCountryCodeViewController.countryCodeSelected = ^(NSString *countryName, NSString *code) {

__strong typeof(weakSelf) strongSelf = weakSelf;

[strongSelf selectedCountryName:countryName andCode:code];

};

UINavigationController *nav = [self navigationControllerWithRootViewController:selectCountryCodeViewController navBarTintColor:AppBlueColor];

[self presentViewController:nav animated:YES completion:nil];

}

//countryCodeSelected //这是一个Block。。。。 要声明它

@property (nonatomic,copy) void(^countryCodeSelected)(NSString *countryName, NSString *code);

3.[strongSelf selectedCountryName:countryName andCode:code];//选择完国家之后的回调函数

- (void)selectedCountryName:(NSString *)countryName andCode:(NSString *)code {

self.countryCodeLabel.text = code;

NSString *placeholder = [NSString stringWithFormat:@"%@ %@", countryName, code];

self.phoneNumberTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:HintTextColor}];

}

这样就完成了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: