8-20学习练习[用两个tableview实现类似省市联动选择效果]
来源:互联网 发布:seo数据分析 编辑:程序博客网 时间:2024/05/16 07:01
在一个View中显示两个tableView,要求使用statedictionary.plist中的数据,其中key作为左边的数据,每点击一个key,在右边的tableView中显示对应的号码列表,并且左边的tableView,前5行为一个分区(title显示top),剩下的为另一个分区(title显示other)
效果图:
问题:1.为什么选择之后取消蓝色背景取消不了
代码:
ViewController.h:
#import <UIKit/UIKit.h>@interface DXWViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>@property (retain, nonatomic) IBOutlet UITableView *TableView1;@property (retain, nonatomic) IBOutlet UITableView *TableView2;@property (retain, nonatomic) NSDictionary *dic;//原始数据@property(retain, nonatomic)NSMutableArray * keys;//可以修改的key(用作分区)@property(retain,nonatomic)NSArray *secArr;//保存某一个key对应的value@end
ViewController.m:
#import "DXWViewController.h"@interface DXWViewController ()@end@implementation DXWViewController- (void)viewDidLoad{ [super viewDidLoad];NSString *path = [[NSBundle mainBundle] pathForResource:@"statedictionary" ofType:@"plist"]; //最原始的数据,不可改变 self.dic = [NSDictionary dictionaryWithContentsOfFile:path]; //NSLog(@"%@",self.dic); self.keys = [[NSMutableArray alloc] init]; NSArray *arr=[self.dic allKeys]; arr = [arr sortedArrayUsingSelector:@selector(compare:)]; self.keys = arr; self.secArr = [[NSArray alloc] initWithArray:[self.dic objectForKey:[self.keys objectAtIndex:0]]]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; }//tableView有多少分区,左边前5行作为一个分区标题top,剩下的为另外一个分区标题other-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if (tableView == self.TableView1) { return 2; } else return 1;}//每个cell显示的内容-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger section = [indexPath section]; NSInteger row = [indexPath row]; if (tableView == self.TableView1) { static NSString *str1 = @"str1"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str1]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str1]; } cell.textLabel.text = [self.keys objectAtIndex:row]; return cell; } else { static NSString *str = @"str"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str]; } cell.textLabel.text = [self.secArr objectAtIndex:row]; return cell; }}//每个分区对应多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (tableView == self.TableView1) { if (section == 0) { return 5; } else { return ([self.keys count] - 5); } } else { return [self.secArr count]; }}//在每个分区Title上显示什么内容-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ if (tableView == self.TableView1) { if (section == 0) { return @"top"; } else { return @"other"; } } else return nil;}//设置索引//-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView//{// if (tableView == self.TableView1) {// return [[NSArray alloc] initWithObjects:@"top",@"other", nil];// }//}//点击选择-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{ if (tableView == self.TableView1) { self.secArr = [[NSArray alloc] initWithArray:[self.dic objectForKey:[self.keys objectAtIndex:[indexPath row]]]]; NSLog(@"%@",self.secArr); //取消选中 [tableView deselectRowAtIndexPath:indexPath animated:YES]; } [self.TableView2 reloadData];}- (void)dealloc { [_TableView1 release]; [_TableView2 release]; [self.secArr release]; [self.dic release]; [self.keys release]; [super dealloc];}@end
- 8-20学习练习[用两个tableview实现类似省市联动选择效果]
- iOS 类似美团外卖 app 两个 tableView 联动效果实现
- iOS 类似美团外卖 app 两个 tableView 联动效果实现
- iOS 类似美团外卖 app 两个 tableView 联动效果实现
- iOS 类似美团外卖 app 两个 tableView 联动效果实现
- IOS TableView实现省市联动
- 用UIPicker做一个类似省市联动选择的例子
- js实现省市联动效果
- silverlight 实现省市联动效果
- axure7实现省市联动效果
- android 省市联动效果实现
- 类似省市联动的查询功能实现
- ios实现两个tableview联动
- ios实现两个tableview联动
- IOS 两个tableview的联动效果
- EXCEL如何做类似省市联动的二级选择菜单?
- js实现省市选择二级联动
- JavaScript实现省市县三级联动效果~~~
- Android 自动滚动的GridView
- x86,I386,i686, x86_64, x64,amd64、Windows Linux AIX下查看CPU位数和操作系统位数、rpm包名
- Magento: Adding category attributes
- R.drawable.id中出现图片id,但是应用中找不到图片资源
- 设计模式六大原则(1):单一职责原则
- 8-20学习练习[用两个tableview实现类似省市联动选择效果]
- log4net 配置速成(保存到数据库)
- 详解slab机制(4) slab初始化
- JSTL 核心标签库 使用
- 怎么修改boot.ini文件
- 用Eclipse打包jar程序直接运行(3.Eclipse打包总结)_hanCSDN_20130821
- 决策树
- 不生成core文件原因
- 状态模式