北京 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省市区字典数组的更多相关文章

  1. iOS开发——MJExtension复杂数组用法

    最近在看MJExtension的Demo,发现了一个plist文件直接转数组模型的方法.以前研究过但是浅尝辄止没有解决,这几天有时间,好好看了看,找到了解决办法,与大家分享. 如果大家的项目中有这种嵌 ...

  2. JSONModel 嵌套字典数组 JSONModel nest NSDictionary NSArray

    JSONModel 嵌套字典数组  JSONModel nest NSDictionary NSArray

  3. JS中遍历普通数组和字典数组的区别

    // 普通数组 var intArray = new Array(); intArray[0] = "第一个"; intArray[1] = "第二个"; fo ...

  4. iOS_字典数组 按key分组和排序

    int main(int argc, const charchar * argv[]) { @autoreleasepool { // 1.定义一个测试的字典数组 NSMutableArray *di ...

  5. iOS对象(字典或数组)转化为JSon字符串

    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:@"he ...

  6. iOS - OC NSDictionary 字典

    前言 @interface NSDictionary<__covariant KeyType, __covariant ObjectType> : NSObject <NSCopyi ...

  7. iOS - Swift Dictionary 字典

    前言 public struct Dictionary<Key : Hashable, Value> : CollectionType, DictionaryLiteralConverti ...

  8. ios nslog 打印字典为中文

    #import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...

  9. 【iOS问题】字典转模型,属性个数不匹配问题

    一.字典转模型的键值对与模型属性不匹配问题 1. 字典的键个数 < 模型的属性个数 (key 能与模型的属性匹配) 1> .KVO 方式: - setValuesForKeysWithDi ...

随机推荐

  1. mysql update连表

    UPDATE price_air_item t1 LEFT JOIN order_item t2 ON t1.ORDER_ITEM_ID = t2.ORDER_ITEM_ID SET t1.BUYER ...

  2. Spring Cloud(2.0)能力大致列表

    微服务九大特性 出自Martin Fowler的<Microservices> 服务组件化 按业务组织团队 做"产品"的态度 智能端点与哑管道 去中心化治理 去中心化管 ...

  3. TensorFlow学习笔记(6):TensorBoard之Embeddings

    本文基于TensorFlow官网的How-Tos写成. TensorBoard是TensorFlow自带的一个可视化工具,Embeddings是其中的一个功能,用于在二维或三维空间对高维数据进行探索. ...

  4. [git 学习篇] --创建git创库

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743256916071d ...

  5. mysql使用日常备忘

    批量插入数据时,如果主键是有业务意义的,并非自自增张,那么有可能在插入的数据中有与已存在的键值重复的,可以用如下方式来插入: INSERT IGNORE 当要插入一个数据时,插入的字段值中主键字段或唯 ...

  6. pytorch conditional GAN 调试笔记

    推荐的几个开源实现 znxlwm 使用InfoGAN的结构,卷积反卷积 eriklindernoren 把mnist转成1维,label用了embedding wiseodd 直接从tensorflo ...

  7. 关闭chrome浏览器的input香蕉黄背景

    chrome浏览器input的自动完成,点击之后自动输入,input的背景会变成香蕉黄,用如下方法修复: /* Change the white to any color ;) 就是给input设置内 ...

  8. 刷题总结——天使玩偶(bzoj2716)

    题目: Description Input Output HINT 题解: 学了cdq后近期最后一道题···然而tm还是搞了1个半小时才tm搞出来······ 先说思路:对于绝对值,我们采取类似于旋转 ...

  9. Static相关

    [理解] 说到static,脑中浮现的几个Key Words是什么? main 类 唯一空间 所有对象共享 static只能处理static 很好,解释一下上面的意思: main static fie ...

  10. [ZJOI2007]最大半连通子图 (Tarjan缩点,拓扑排序,DP)

    题目链接 Solution 大概是个裸题. 可以考虑到,如果原图是一个有向无环图,那么其最大半联通子图就是最长的一条路. 于是直接 \(Tarjan\) 缩完点之后跑拓扑序 DP就好了. 同时由于是拓 ...