UI 08 tableView版中国省市区 -- 3页
来源:互联网 发布:服务器数据备份方案 编辑:程序博客网 时间:2024/06/01 07:11
还记得之前写的中国省市区么?
现在我们使用tableView将他显示出来.
里面用到了从前向后属性传值.
第一页效果图如下, 一共31个省
#import "ProViewController.h"#import "CityViewController.h"@interface ProViewController ()<UITableViewDataSource,UITableViewDelegate>@property(nonatomic, retain)NSMutableArray *proArr;@end@implementation ProViewController- (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/UI 学习/UI08TableView 省市区./UI08TableView 省市区./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 setObject:temp forKey:@"cityname"]; NSMutableArray *zonearr = [NSMutableArray array]; [citydic setObject: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.navigationController.navigationBar.translucent = NO; self.view.backgroundColor = [UIColor redColor]; self.title = @"中国省名"; 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.delegate = self; tableView.dataSource = self;// // 读出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;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease]; } NSMutableDictionary *prodic = self.proArr[indexPath.row]; cell.textLabel.text = prodic[@"proname"]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ CityViewController *cityVC = [[CityViewController alloc] init]; [self.navigationController pushViewController:cityVC animated:YES]; [cityVC release]; // 省字典 NSMutableDictionary *prodic = self.proArr[indexPath.row]; //省对应的市数组 cityVC.cityarr = prodic[@"cityarr"];}
第二页:
#import "CityViewController.h"#import "ZoomViewController.h"@interface CityViewController ()<UITableViewDataSource, UITableViewDelegate>@end@implementation CityViewController- (void)dealloc{ [_cityarr release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor blueColor]; // NSLog(@"%@",self.cityarr); self.title = @"市名"; UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped]; [self.view addSubview:tableView]; [tableView release]; tableView.delegate = self; tableView.dataSource = self;}- (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] autorelease]; } NSMutableDictionary *citydic = self.cityarr[indexPath.row]; cell.textLabel.text = citydic[@"cityname"]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ ZoomViewController *zoneVC = [[ZoomViewController alloc] init]; [self.navigationController pushViewController:zoneVC animated:YES]; [zoneVC release]; NSMutableDictionary *citydic = self.cityarr[indexPath.row]; zoneVC.zonearr = citydic[@"zonearr"];}
第三页:
#import "ZoomViewController.h"@interface ZoomViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>@property(nonatomic, retain)UIAlertView *alet;@end@implementation ZoomViewController- (void)dealloc{ [_zonearr release]; [_alet release]; [super dealloc];}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"区名"; self.view.backgroundColor = [UIColor greenColor]; 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.delegate = self; tableView.dataSource = self; tableView.rowHeight = 100; self.alet = [[UIAlertView alloc] initWithTitle:@"要返回到市名吗?" message:nil delegate:self cancelButtonTitle:@"返回市名" otherButtonTitles:@"返回主页",@"Cancel", nil];}- (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:UITableViewCellStyleSubtitle reuseIdentifier:reuse] autorelease]; } cell.textLabel.text = self.zonearr[indexPath.row]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [self.alet show];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == 0) { [self.navigationController popViewControllerAnimated:YES]; }else if (buttonIndex == 1){ [self.navigationController popToRootViewControllerAnimated:YES]; }}
0 0
- UI 08 tableView版中国省市区 -- 3页
- UI 09 tableView 中国省市区. 一个页面, 三个tableView
- 省市区3个tableView联动实现
- tableView联动(省市区)
- 省市区字典数组嵌套(UI版)
- 中国地名省市区xml
- 获取中国 省市区 js
- 中国省市区----SQL表
- 中国省市区脚本
- 中国省市区数据mysql脚本
- 动态构建TreeView(中国省市区)
- OC字典练习 -- 中国省市区
- 中国省市区--地区SQL表
- IOS下省市区选择器实现[基于TableView]
- IOSUI课堂笔记用TableView实现省市区
- TableView省市区数组字典 属性传值
- UI10_3个tableView的省市区联动
- 三个tableView的联动(省市区数组)
- STL中的函数对象(一)
- CodeForces 389A Fox and Number Game
- 使用HttpURLConnection下载图片
- TCP/IP网络常用名词缩写
- input中加入图片的做法
- UI 08 tableView版中国省市区 -- 3页
- 杭电 HDU ACM 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
- 社説 20150829 新国立競技場 五輪へ失策はもう許されない
- Java 温故
- softmax regression分类相关
- 大小端字节序
- poj4549 费马小定理+矩阵快速幂取余
- JNI_最简单的Java调用C/C++代码
- NSUserDefault保存的Plist文件在(真机/模拟器)沙盒路径中的位置