北京 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
红桥区......
#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];
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.proArr.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] 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];
}
@end
#import <UIKit/UIKit.h>
@interface CityViewController : UIViewController
@property(nonatomic,retain)NSArray *cityArr;
@end
#import "CityViewController.h"
#import "ZoneViewController.h"
@interface CityViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation CityViewController
- (void)viewDidLoad {
[super viewDidLoad];
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];
}
-(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];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import <UIKit/UIKit.h>
@interface ZoneViewController : UIViewController
@property(nonatomic,retain)NSArray *zoneArr;
@end
#import "ZoneViewController.h"
@interface ZoneViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation ZoneViewController
- (void)viewDidLoad {
[super viewDidLoad];
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];
}
@end