iOS UI08_tableView省市区字典数组
2017-07-24 09:51
197 查看
北京 1 北京市 1 西城区 1 东城区 2 崇文区 3 宣武区 4 朝阳区 5 丰台区 6 石景山区 7 海淀区 8 门头沟区 9 房山区 10 通州区 11 顺义区 12 昌平区 13 大兴区 14 怀柔区 15 平谷区 16 密云区 17 延庆区 18 天津 2 天津市 2 和平区 19 河东区 20 河西区 21 南开区 22 河北区 23 红桥区......
// // MainViewController.m // UI08_tableView省市区字典数组 // // Created by dllo on 15/8/7. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "MainViewController.h" #import "CityViewController.h" @interface MainViewController ()<UITableViewDataSource,UITableViewDelegate> @property(nonatomic,retain)NSMutableArray *proArr; @end @implementation MainViewController -(void)dealloc { [_proArr release]; [super dealloc]; } //初始化方法 -(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { [self createData]; }return self; } -(void)createData { //文件的路径 NSString *path=@"/Users/dllo/Desktop/作业 /UI08_tableView省市区字典数组/UI08_tableView省市区字典数组/area.txt"; NSString *str =[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSArray *strArr=[str componentsSeparatedByString:@"\n"]; self.proArr=[NSMutableArray array]; //省市区数组 for(NSString *temp in strArr){ if (![temp hasPrefix:@" "]) { NSMutableDictionary *proDic=[NSMutableDictionary dictionary]; [proDic setObject:temp forKey:@"proName"]; NSMutableArray *cityArr=[NSMutableArray array]; [proDic setObject:cityArr forKey:@"cityArr"]; [self.proArr addObject:proDic]; }else if ([temp hasPrefix:@" "] && ![temp hasPrefix:@" "]) { NSMutableDictionary *cityDic=[NSMutableDictionary dictionary]; [cityDic setValue:temp forKey:@"cityName"]; NSMutableArray *zoneArr=[NSMutableArray array]; [cityDic setValue:zoneArr forKey:@"zoneArr"]; NSMutableDictionary *proDic=[self.proArr lastObject]; NSMutableArray *cityArr=proDic[@"cityArr"]; [cityArr addObject:cityDic]; }else { NSMutableDictionary *proDic=[self.proArr lastObject]; NSMutableArray *cityArr=proDic[@"cityArr"]; NSMutableDictionary *cityDic=[cityArr lastObject]; NSMutableArray *zoneArr=cityDic[@"zoneArr"]; [zoneArr addObject:temp]; } } } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor cyanColor]; self.navigationController.navigationBar.translucent=NO; self.navigationItem.title=@"省"; UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -64) style:UITableViewStylePlain]; tableView.dataSource=self; tableView.delegate=self; [self.view addSubview:tableView]; [tableView release]; // //读出plist文件内容 // NSString *path=[[NSBundle mainBundle] pathForResource:@"Student" ofType:@"plist"]; // NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithContentsOfFile:path]; // NSLog(@"%@",dic); } //分区有多少行,和数组中元素个数一致 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.proArr.count; } //创建cell -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuse=@"reuse"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease]; } //省字典 NSMutableDictionary *proDic=self.proArr[indexPath.row]; cell.textLabel.text=proDic[@"proName"]; return cell; } //点击触发的方法 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 省字典 NSMutableDictionary *proDic=self.proArr[indexPath.row]; //省相应的市数组 NSMutableArray *cityArr=proDic[@"cityArr"]; CityViewController *cityVC=[[CityViewController alloc] init]; cityVC.cityArr=cityArr; [self.navigationController pushViewController:cityVC animated:YES ]; [cityVC release]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
// // CityViewController.h // UI08_tableView省市区字典数组 // // Created by dllo on 15/8/7. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import <UIKit/UIKit.h> @interface CityViewController : UIViewController @property(nonatomic,retain)NSArray *cityArr; @end
// // CityViewController.m // UI08_tableView省市区字典数组 // // Created by dllo on 15/8/7. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "CityViewController.h" #import "ZoneViewController.h" @interface CityViewController ()<UITableViewDataSource,UITableViewDelegate> @end @implementation CityViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor cyanColor]; self.navigationController.navigationBar.translucent=NO; self.navigationItem.title=@"市"; UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain]; tableView.dataSource=self; tableView.delegate=self; [self.view addSubview:tableView]; // [tableView release]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.cityArr.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuse=@"reuse"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse]; } NSMutableDictionary *cityDic=self.cityArr[indexPath.row]; cell.textLabel.text=cityDic[@"cityName"]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //市字典 NSMutableDictionary *cityDic=self.cityArr[indexPath.row]; NSMutableArray *zoneArr=cityDic[@"zoneArr"]; ZoneViewController *zoneVC=[[ZoneViewController alloc] init]; zoneVC.zoneArr=zoneArr; [self.navigationController pushViewController:zoneVC animated:YES]; // [zoneVC release]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
// // ZoneViewController.h // UI08_tableView省市区字典数组 // // Created by dllo on 15/8/7. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import <UIKit/UIKit.h> @interface ZoneViewController : UIViewController @property(nonatomic,retain)NSArray *zoneArr; @end
// // ZoneViewController.m // UI08_tableView省市区字典数组 // // Created by dllo on 15/8/7. // Copyright (c) 2015年 zhozhicheng. All rights reserved. // #import "ZoneViewController.h" @interface ZoneViewController ()<UITableViewDataSource,UITableViewDelegate> @end @implementation ZoneViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor orangeColor]; self.navigationController.navigationBar.translucent=NO; self.navigationItem.title=@"区"; UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain]; tableView.dataSource=self; tableView.delegate=self; [self.view addSubview:tableView]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.zoneArr.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuse=@"reuse"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] ; } cell.textLabel.text=self.zoneArr[indexPath.row]; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
相关文章推荐
- iOS UI08_tableView省市区字典数组
- 一个TableView实现省市区字典数组的跳转
- TableView省市区数组字典 属性传值
- "IOS"空件TableView中,字典,数组的套用........
- UI_UITableView省市区字典数组
- UITableView 数组与字典结合(省市区)
- UI09_多种UITableView(一个界面出现三个tableView,省市区数组)
- UI09_UITableView省市区字典数组
- OC-省市区字典数组
- 关于数组切换控制tableview的section切换问题
- iOS OC06_省市区字典数组
- OC省市区数组套字典小结
- iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
- iOS学习- 12 绑定数组数据到Table View - Todo App
- 今天在写TableView的时候,懒加载了模型数组同时覆写了setter方法,报错了
- 一个页面创建多个tableView 相关联(省市区数组)
- UI10_3个tableView的省市区联动
- Objective-C 经典字典数组排序 - 省市区
- UITableView省市区字典
- 一个页面创建多个tableView 相关联(省市区数组)