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}];
}
这样就完成了
// 初始化手机号国家前缀按钮
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}];
}
这样就完成了
相关文章推荐
- 如何从iOS Developer 中下载xcode dmg
- IOS 瀑布流
- 多态
- iOS通过经纬度计算两个坐标之间的距离
- iOS经典讲解之实现上拉刷新和下拉刷新
- Xcode7真机调试iOS应用程序
- iOS项目更新之升级Xcode7 & iOS9
- iOS 全局变量PCH文件的使用
- iOS之通知传值的使用
- ios framework添加
- IOS开发中的几种设计模式介绍
- iOS---仿京东分类菜单实例实现
- iOS开发——设计模式那点事
- iOS 调试技巧
- [转] iOS --- 我的iOS工程结构
- 防止在iOS设备中的Safari将数字识别为电话号码
- iOS 开发中遇到的问题
- 解析iOS开发中的FirstResponder第一响应对象
- iOS关于应用内分享
- ios 如何隐藏状态栏