省市区字典数组嵌套(UI版)
来源:互联网 发布:js在线客服插件 编辑:程序博客网 时间:2024/06/06 21:39
// AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; NSString *filePath = @"/Users/dllo/Desktop/textPCA/textPCA/area-2.txt"; NSString *string = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; NSArray *mArray = [string componentsSeparatedByString:@"\n" ]; NSCharacterSet *cSet = [NSCharacterSet characterSetWithCharactersInString:@" 0123456789"]; // 字符的集合 NSMutableArray *array = [NSMutableArray array]; // 空数组 NSDictionary *rootDic = [NSDictionary dictionaryWithObjectsAndKeys:array, @"array", @"地区", @"name", nil]; // 根字典 for (NSString *s in mArray) { NSRange r = {0, 2}; NSString *s1 = [s substringWithRange:r]; NSMutableDictionary *superDic = [NSMutableDictionary dictionaryWithDictionary:rootDic]; while ([s1 isEqualToString:@" "]) { // 几个@" "决定装到第哪层的字典里面 r.location += 2; s1 = [s substringWithRange:r]; superDic = [superDic[@"array"] lastObject]; // 得到这个地方的字典的父字典 } NSString *name = [s stringByTrimmingCharactersInSet:cSet]; // 字符串剔除在字符集合的字符,得到城市名字的字符串 array = [NSMutableArray array]; // 新的空数组 NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:name, @"name", array, @"array", nil]; // 生成的新的字典,地方名和一个空数组 [superDic[@"array"] addObject:dic]; // 把字典加在父字典的数组里 [dic setObject:superDic forKey:@"superDic" ]; // 找到子字典的父字典 } MainViewController *mainViewController = [[MainViewController alloc]init]; UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:mainViewController]; [mainViewController release]; mainViewController.dic = rootDic; self.window.rootViewController = navigationController; [navigationController release]; return YES;}
#import "MainViewController.h"@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>@end@implementation MainViewController- (void)viewDidLoad { [super viewDidLoad]; self.navigationController.navigationBar.translucent = NO; // Do any additional setup after loading the view. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain]; [self.view addSubview:tableView]; [tableView release]; tableView.dataSource = self; tableView.delegate = self; tableView.rowHeight = 30; self.title = self.dic[@"name"];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return ((NSArray *)self.dic[@"array"]).count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse]; } cell.textLabel.text = self.dic[@"array"][indexPath.row][@"name"]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (((NSArray *)self.dic[@"array"][indexPath.row][@"array"]).count) { MainViewController *anotherVC = [[MainViewController alloc] init]; [self.navigationController pushViewController:anotherVC animated:YES]; anotherVC.dic = self.dic[@"array"][indexPath.row]; [anotherVC release]; }}@end
0 0
- 省市区字典数组嵌套(UI版)
- OC数组和字典嵌套练习:省市区
- OC-可变数组-可变字典嵌套(练习-省市区)
- 一个关于中国省市区的字典,数组嵌套使用
- 基于 Objective-C OC的省市区代码(字典数组嵌套)
- objective-c 省市区练习(数组与字典的嵌套)
- OC_省市区字典数组
- 省市区字典数组
- OC-省市区字典数组
- 省市区字典数组
- 省市区字典数组
- UI08_tableview省市区字典数组
- UI09_UITableView省市区字典数组
- UI_UITableView省市区字典数组
- 省市区 数组套字典 字典套数组
- iOS OC06_省市区字典数组
- iOS UI08_tableView省市区字典数组
- #Objective-C 之 省市区 (数组-字典-数组-字典-数组)
- hd1002
- hdu 5303 Delicious Apples (DP+枚举)
- socket绑定INADDR_ANY
- Java Type VS Hibernate Type
- 《Unix网络编程卷1-套接字联网API》第一个例子编译
- 省市区字典数组嵌套(UI版)
- MATLAB 概率统计
- libpcap函数详解
- java
- 数据流重定向
- 杭电2005 第几天 函数形式
- C语言中内联函数的作用 inline
- 每天一个小知识点12(jQueryMobile总结三)
- Dom4j使用