三个tableView的联动(省市区数组)
来源:互联网 发布:linux查看端口nc 编辑:程序博客网 时间:2024/05/01 01:40
三个tableView的联动,分为两部分(1.省市区数组的数据解析)(2.判断是哪个tableView,显示不同的cell)
需要在点击方法里获取需要操作的数组
因为是三个tableView,只有一个tableView可以适应高度,其他的需要设置.两种办法1.将导航控制栏的透明度变成NO.但是需要在高度的基础上-64
// 这种设置,需要在高度的基础上-64// self.navigationController.navigationBar.translucent = NO;
第2种方法:内嵌的方式(只有第一个tableView适配) 但是有一个属性,只会让第一个滚动视图适应屏幕,从第二个开始就不管了,要是想保留半透明的效果,要把属性设置成NO,然后再设置滚动视图的坐标位置(将纵坐标+64,高度-64)关键词auto
// 内嵌的方式(只有第一个tableView适配) // 这个属性只会让第一个滚动视图适应屏幕,从第二个开始就不管了,要是想保留半透明的效果了把属性设置成NO,然后再设置滚动视图的坐标位置 // 记得将 纵坐标+64,然后将 高度-64 self.automaticallyAdjustsScrollViewInsets = NO;
获取数据,省市区字典(省数组中放省字典,省字典放第一对key:省名 value:省的字符串 ; 第二对key:市数组 value:市数组 市数组中放市字典, 第一对key:市名 value:市的字符串 第二对key:区数组 value:区数组, 区数组中放字符串就可以)
- (void)createData{ NSString *path = @"/Users/dllo/Desktop/课程/OC/area.txt"; NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSArray *strArr = [str componentsSeparatedByString:@"\n"];// NSLog(@"%@", strArr); 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"];<h2> // 将数组加入到字典的时候,需要注意</h2> 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]; } } }
tableView的协议中,需要判断具体是哪个tableView 两种方法1.通过tag值和协议方法和tableView对象进行比较(tableView.tag == 1000) 2.控件写成了属性,然后判断地址是否相同(self.proTableView == tableView)
1.点击方法,先判断tableView,然后获取内容,最后不要忘记刷新内存!!!!!!!!!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 需要判断点击的是哪一个tableView // 1.通过tag值,和协议方法的tableView对象进行比较 // 2.控件写成属性,然后判断地址是否相同 // 用tag值判断(tableView.tag == 1000) if (self.proTableView == tableView) { self.cityArr = self.proArr[indexPath.row][@"cityArr"]; // 不要忘记刷新 [self.cityTableView reloadData]; } else if (self.cityTableView == tableView){ self.zoneArr = self.cityArr[indexPath.row][@"zoneArr"]; [self.zoneTableView reloadData]; }}
2.判断行数的协议方法,判断tableView,不同的tableView对应不同的数组数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // 需要判断 if (self.proTableView == tableView) { return self.proArr.count; } else if(self.cityTableView == tableView) { return self.cityArr.count; } else { return self.zoneArr.count; } }
3.cell的协议方法,判断,取值就可以了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.proTableView == tableView) { static NSString *reuse = @"reuse"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease]; } NSMutableDictionary *dic = self.proArr[indexPath.row]; cell.textLabel.text = dic[@"proName"]; return cell; } else if (self.cityTableView == tableView){ static NSString *reuse = @"city"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease]; } cell.textLabel.text = self.cityArr[indexPath.row][@"cityName"]; return cell; } else { static NSString *reuse = @"zone"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease]; }
// cell.textLabel.text = self.zoneArr[indexPath.row]; return cell; } }
0 0
- 三个tableView的联动(省市区数组)
- Objective-C 省市区 三个tableView联动
- UI10_3个tableView的省市区联动
- tableView联动(省市区)
- UI_三个UITableView的省市区联动
- UI09_多种UITableView(一个界面出现三个tableView,省市区数组)
- 三个tableView联动
- 省市区3个tableView联动实现
- 一个TableView实现省市区字典数组的跳转
- UI 09 tableView 中国省市区. 一个页面, 三个tableView
- 省市区三级联动的js
- TableView省市区数组字典 属性传值
- 省市区三级联动(数组、JSON实现)
- 06.TableView的联动
- 省市区联动
- 使用ajax写的省市区三级联动
- 超好用的JS省市区三级联动
- jquery + 数据库的省市区三级联动
- 关于Busybox对interfaces文件的解析过程
- 88. Merge Sorted Array
- UVA 1471 Defense Lines
- Arduino - 软串口
- span标签 设置宽度
- 三个tableView的联动(省市区数组)
- apache ab.exe压力测试
- java性能优化读书笔记之三《程序优化===集合优化(Map)》
- jsp、freemarker、velocity对比
- 固定SessionID 漏洞 攻击(session fixation attacks)
- Android版添加phonegap-读取手机短信插件教程
- 给元素绑定事件时传参
- 使用Touch ID指纹解锁
- 1-1-绪论-第1章-《数据结构》课本源码-严蔚敏吴伟民版