ios pickerview选择城市
来源:互联网 发布:ubuntu开机花屏 编辑:程序博客网 时间:2024/03/28 17:55
//// ViewController.m// 02-城市选中//// Created by panba on 16-4-12.// Copyright (c) 2016年 panba. All rights reserved.//#import "ViewController.h"#import "JCCities.h"@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>@property(nonatomic,strong) NSArray *cities;@property(nonatomic,strong) UIPickerView *pickerView;@end@implementation ViewController//0-viewdidload- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //1-添加一个pickerview UIPickerView *pickerView = [[UIPickerView alloc]init]; //pickerView.frame = CGRectMake(0, 80, 320, 400); pickerView.dataSource = self; pickerView.delegate = self; self.pickerView = pickerView; [self.view addSubview:pickerView];}//1-懒加载-(NSArray *)cities{ if (_cities ==nil) { //1-找到路径 NSString *fullPath = [[NSBundle mainBundle]pathForResource:@"cities.plist" ofType:nil]; //2-加载数据 NSArray *array = [NSArray arrayWithContentsOfFile:fullPath]; NSMutableArray *model = [[NSMutableArray alloc]initWithCapacity:array.count]; for (NSDictionary *dict in array) { JCCities *city = [JCCities citiesWithDict:dict]; [model addObject:city]; } _cities = [model copy]; } return _cities;}//2-返回pickerview的行数-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2;}//2.1返回每一组的行数-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ if (component == 0) { return self.cities.count; }else { //1-获得到第0列选中第是第几行 NSInteger index = [self.pickerView selectedRowInComponent:0]; //2-然后得到这一个数组中城市第数组cities JCCities *city = self.cities[index]; NSArray *cities = city.cities; //3-返回城市数组第count return cities.count; }}-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ if (component ==0) { //NSInteger index = [self.pickerView selectedRowInComponent:0]; JCCities *cities = self.cities[row]; return cities.name; }else { //1-获得第0行的被选中的行数 NSInteger index = [self.pickerView selectedRowInComponent:0]; //2-得到这一个数组中的cities数组 JCCities *city = self.cities[index]; NSArray *cities = city.cities; //3-返回这一个数组中的城市名称 NSString *citiName = cities[row]; return citiName; }}//监听pickview的选中操作-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ if (0==component) { [self.pickerView reloadComponent:1]; //让第1列自动滚到第0行 [self.pickerView selectRow:0 inComponent:1 animated:YES]; }}@end
0 0
- ios pickerview选择城市
- 城市选择pickerView
- ios选择城市
- iOS开发-选择城市
- ios选择城市
- iOS pickerView
- PickerView时间 城市 条件选择器
- 地址选择 PickerView
- PickerView滚轮选择
- IOS pickerView 使用
- iOS 自定义PickerView
- ios pickerView 点菜
- iOS tableView和pickerView
- 仿ios的PickerView
- PickerView时间,地点选择视图
- 城市选择
- 城市选择
- PickerView可以滑动选择的pickerView工具类(转载)
- 二分算法problem1001
- 切入业务日志
- LeetCode 160. Intersection of Two Linked Lists
- iOS 通知传值(顺传)
- bzoj2705【SDOI2012】Longge的问题
- ios pickerview选择城市
- Android ListView实现上拉到底部的时候自动刷新数据
- 98%的人没解出的德国面试逻辑题(离散数学篇)!?
- win10 wamp 无法启动 红色
- bzoj3004 吊灯
- javascript函数apply的使用和理解
- 关于python3.2的'dict' object has no attribute 'iteritems'
- Android 深入理解Android中的自定义属性
- bzoj3007 拯救小云公主