iOS控件-3级城市列表-plist版
2024-09-02 10:12:33
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
plist部分:
调用部分:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
WJCityPikerView *piker = [[WJCityPikerView alloc]initWithModelBlock:^(WJPikerDataModel *model) {
NSLog(@"%@ %@ %@ %@ %@ %@",model.provinceName,model.cityName,model.disName,model.provinceId,model.cityId,model.disId);
[self.view endEditing:YES];
} backBlock:^{
NSLog(@"返回");
[self.view endEditing:YES];
}];
textField.inputView = piker;
}
内部:
1.取出plist中的信息
//总数据
- (NSArray *)dataArray {
if (!_dataArray) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"city" ofType:@"plist"];
_dataArray = [[NSArray alloc]initWithContentsOfFile:plistPath];
}
return _dataArray;
}
2.创建省,市,区三个数组分别装查找到的省市区的信息
@property (nonatomic,strong)NSMutableArray *provenceArray;
@property (nonatomic,strong)NSMutableArray *cityArray;
@property (nonatomic,strong)NSMutableArray *areaArray;
3.滚动滚轮在数组里面查找省市区的信息并将他们添加到相应的数组中
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (component) {
case :
{
WJCityPlist *plist2 = self.provenceArray[row];
self.cityArray = [[NSMutableArray alloc]init];
[self.dataArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL * _Nonnull stop) {
if ([dic[@"pid"]integerValue] == [plist2.Id integerValue]) {
WJCityPlist *plist = [[WJCityPlist alloc]initWithDic:dic];
[self.cityArray addObject:plist];
}
}];
WJCityPlist *plist3 = self.cityArray[];
self.areaArray = [[NSMutableArray alloc]init];
[self.dataArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL * _Nonnull stop) {
if ([dic[@"pid"]integerValue] == [plist3.Id integerValue]) {
WJCityPlist *plist = [[WJCityPlist alloc]initWithDic:dic];
[self.areaArray addObject:plist];
}
}];
[_piker selectRow: inComponent: animated:NO];
[_piker reloadAllComponents];
[_piker reloadComponent:];
[_piker reloadComponent:];
_indexprovence = row;
break;
}
case :
{
WJCityPlist *plist3 = self.cityArray[row];
self.areaArray = [[NSMutableArray alloc]init];
[self.dataArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL * _Nonnull stop) {
if ([dic[@"pid"]integerValue] == [plist3.Id integerValue]) {
WJCityPlist *plist = [[WJCityPlist alloc]initWithDic:dic];
[self.areaArray addObject:plist];
}
}];
[_piker selectRow: inComponent: animated:NO];
[_piker reloadComponent:];
_indexcity = row;
}
break;
case :
_indexaera = row;
break;
default:
break;
}
NSLog(@"%ld %ld %ld",_indexprovence,_indexcity,_indexaera);
}
效果图:
最新文章
- Couchbase N1QL
- 第22章 DLL注入和API拦截(1)
- PHP使用DateTime类做时间日期到字符串转换
- 打开开源项目总得.md文件
- bzoj 2141 线段树套平衡树
- HTML5-Video &; Audio
- 【原创】海量数据处理问题(一) ---- 外排,堆排,K查找的应用
- CentOS安装mplayer
- bootstrap-datetimepicker 时间表箭头不能显示
- system2之:4-文件系统管理(上)
- 使用MiniProfiler调试Asp.net Mvc性能
- keepalive的 nopreempt 非抢占
- 2015最新iOS学习线路图
- tablesorter 的使用
- DB 查询分析器 6.03 ,遨游于任何Windows操作系统之上的最优秀的数据库客户端工具
- Springboot 系列(三)Spring Boot 自动配置原理
- MT【316】常数变易法
- 语音识别传统方法(GMM+HMM+NGRAM)概述
- Android源码分析一 Android系统架构
- boost::bind 实现原理, 手动实现一个
热门文章
- you don't have permission to access / on this server解决
- C# DataTable的詳細用法 (转)
- (十一)mybatis之映射器(select)
- Invalid bound statement (not found): com.ros.dao.LogMapper.insert
- Python学习日志9月15日
- 数据库_7_SQL基本操作——表操作
- 计算机图形学:贝塞尔曲线(Bezier Curve)
- gson对象的相互转换
- ios设备屏幕尺寸与分辨率
- NSLayoutConstraint.constraintsWithVisualFormat详解,以及AlignAllCenterY