iOS UI08_tableView省市区字典数组
北京 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省市区字典数组的更多相关文章
- iOS开发——MJExtension复杂数组用法
最近在看MJExtension的Demo,发现了一个plist文件直接转数组模型的方法.以前研究过但是浅尝辄止没有解决,这几天有时间,好好看了看,找到了解决办法,与大家分享. 如果大家的项目中有这种嵌 ...
- JSONModel 嵌套字典数组 JSONModel nest NSDictionary NSArray
JSONModel 嵌套字典数组 JSONModel nest NSDictionary NSArray
- JS中遍历普通数组和字典数组的区别
// 普通数组 var intArray = new Array(); intArray[0] = "第一个"; intArray[1] = "第二个"; fo ...
- iOS_字典数组 按key分组和排序
int main(int argc, const charchar * argv[]) { @autoreleasepool { // 1.定义一个测试的字典数组 NSMutableArray *di ...
- iOS对象(字典或数组)转化为JSon字符串
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:@"he ...
- iOS - OC NSDictionary 字典
前言 @interface NSDictionary<__covariant KeyType, __covariant ObjectType> : NSObject <NSCopyi ...
- iOS - Swift Dictionary 字典
前言 public struct Dictionary<Key : Hashable, Value> : CollectionType, DictionaryLiteralConverti ...
- ios nslog 打印字典为中文
#import <Foundation/Foundation.h> @implementation NSDictionary (Log) - (NSString *)description ...
- 【iOS问题】字典转模型,属性个数不匹配问题
一.字典转模型的键值对与模型属性不匹配问题 1. 字典的键个数 < 模型的属性个数 (key 能与模型的属性匹配) 1> .KVO 方式: - setValuesForKeysWithDi ...
随机推荐
- Spider爬虫-get、post请求
1:概念: 爬虫就是通过编写程序,模拟浏览器上网,然后让其去互联网上抓取数据的过程. 2:python爬虫与其他语言的比较: (1)php爬虫弊端:多进程多线程支持的不好 (2)java:代码臃肿,重 ...
- SPFA ----模板 O(kE) (k一般不超过2)
原理:若一个点入队的次数超过顶点数V,则存在负环: #include "bits/stdc++.h" using namespace std; ; struct Edge { in ...
- 如何杀死linux-zombie僵尸进程
百科: ZOMBIE:僵尸状态,表示进程结束但尚未消亡的一种状态,此时进程已经结束运行并释放大部分资源,但尚未释放进程控制块. 与ZOMBIE对应的进程状态还有RUNNING(正在运行或等待运行状态) ...
- Event based Collections
https://sourceforge.net/p/happy-guys/wiki/Event%20based%20Collections/
- linux磁盘问题排查
一.ls $>>ls /data* //查看有无input/output error报错 二.demsg $>>demsg|grep sd 问题盘结果: 三.iostat使用 ...
- SPOJ 3267 D-query(离散化+在线主席树 | 离线树状数组)
DQUERY - D-query #sorting #tree English Vietnamese Given a sequence of n numbers a1, a2, ..., an and ...
- 算法复习——1D/1Ddp优化
搬讲义~~~~ 题目1:玩具装箱(bzoj1010) Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一 ...
- js 打印二维码
先简单说一下jquery-qrcode,这个开源的三方库(可以从https://github.com/jeromeetienne/jquery-qrcode 获取), qrcode.js 是实现二维码 ...
- bzoj 3924 幻想乡战略游戏
题目大意: 有边权点权的树,动态修改点权 每次修改后求带权重心x (\(minimize\) \(S=\sum_i val[i]*dist[x][i]\)) 分析: 从暴力找突破口: 对于边x,y,设 ...
- 我要好offer之 搜索算法大总结
1. 二分搜索 详见笔者博文:二分搜索的那些事儿,非常全面 2. 矩阵二分搜索 (1) 矩阵每行递增,且下一行第一个元素大于上一个最后一个元素 (2) 矩阵每行递增,且每列也递增 3. DFS 深度优 ...