207,省市联动效果
来源:互联网 发布:baidu软件中心 编辑:程序博客网 时间:2024/06/03 01:57
JSProvince.h:
#import <Foundation/Foundation.h>
@interface JSProvince : NSObject
@property(nonatomic,copy)NSString *name;
@property(nonatomic,copy)NSArray *cities;
-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)provinceWithDict:(NSDictionary *)dict;
@end
JSProvince.m:
#import "JSProvince.h"
@implementation JSProvince
-(instancetype)initWithDict:(NSDictionary *)dict{
if (self = [superinit]) {
[selfsetValuesForKeysWithDictionary:dict];
}
return self;
}
+(instancetype)provinceWithDict:(NSDictionary *)dict{
return [[selfalloc] initWithDict:dict];
}
@end
JSViewController.m:
#import "JSViewController.h"
#import "JSProvince.h"
@interface JSViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property(nonatomic,strong)NSArray *provinces;
@property (weak, nonatomic) IBOutletUIPickerView *pickerView;
@property (nonatomic,assign)int provinceIndex;//省份选中索引
@end
@implementation JSViewController
-(NSArray *)provinces{
if (_provinces ==nil) {
NSMutableArray *provincesTmp = [NSMutableArrayarray];
NSString *path = [[NSBundlemainBundle] pathForResource:@"provinces"ofType:@"plist"];
NSArray *data = [NSArrayarrayWithContentsOfFile:path];
for (NSDictionary *dictin data) {
JSProvince *province = [JSProvinceprovinceWithDict:dict];
[provincesTmp addObject:province];
}
_provinces = provincesTmp;
}
return_provinces;
}
- (void)viewDidLoad
{
[superviewDidLoad];
NSLog(@"%@",self.provinces);
}
//两组
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
//第一组
if (component == 0) {
return self.provinces.count;
}else{
//第二组
JSProvince *province = self.provinces[_provinceIndex];
return province.cities.count;
}
}
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
if (component == 0) {
return 100;
}else{
return 80;
}
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = nil;
if (view == nil) {
label =[[UILabel alloc] init];
}else{
label = (UILabel *)view;
}
if (component == 0) {
JSProvince *province = self.provinces[row];
label.text = province.name;
label.backgroundColor = [UIColoryellowColor];
}else{
JSProvince *province = self.provinces[_provinceIndex];
label.text = province.cities[row];
label.backgroundColor = [UIColorgrayColor];
}
return label;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if (component == 0) {
_provinceIndex = row;
[pickerView reloadComponent:1];
[pickerView selectRow:0inComponent:1animated:YES];
}
}
@end
- 207,省市联动效果
- 省市联动效果
- js实现省市联动效果
- silverlight 实现省市联动效果
- javascript省市二级联动效果
- axure7实现省市联动效果
- android 省市联动效果实现
- JavaScript实现省市县三级联动效果~~~
- JavaScript实现省市县三级联动效果~~~
- 基于jQuery+JSON的省市联动效果
- 基于jQuery+JSON的省市联动效果
- 基于jQuery+JSON的省市联动效果
- 省市联动
- 省市联动
- 省市联动
- 省市联动
- 省市联动
- 省市联动
- WebView的简单讲解
- JavaScript > 使用JSONP或HttpClient跨域请求
- 设计模式之Builder模式
- MySql导入导出数据库(含远程导入导出)
- Swing Synth L&F
- 207,省市联动效果
- Visual Studio CUDA文件高亮设置 win10+VS2015+CUDA7.5
- 进入保护模式(一)——《x86汇编语言:从实模式到保护模式》读书笔记12
- c语言学习
- 在TextView周围添加图片
- 第2章 基础语法 — 循环语句
- android animation rotate to specific angle
- VC 生成 exe 可执行程序 然后在cmd窗口调用
- Generating project in Batch mode 很慢的问题