类似于QQ列表展开和收起的列表
来源:互联网 发布:js替换file属性input 编辑:程序博客网 时间:2024/05/16 18:32
#import "ViewController.h"#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width@interface ViewController () <UITableViewDataSource,UITableViewDelegate>@property (nonatomic,strong)UITableView *tabelView;@property (nonatomic,strong)NSMutableArray *array;@property (nonatomic,strong)NSMutableDictionary *dict;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //创建tableView self.tabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain]; self.tabelView.delegate = self; self.tabelView.dataSource = self; [self.view addSubview:self.tabelView]; //记录的字典 self.dict = [NSMutableDictionary dictionary]; //每组的标题 self.array = [[NSMutableArray alloc] init]; //去除tableView多余的横线 self.tabelView.tableFooterView = [[UIView alloc] init]; for(int i=0;i<5;i++){ NSString *str = [NSString stringWithFormat:@"第%d组",i]; [self.array addObject:str]; }}//每组的组头- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)]; view.backgroundColor = [UIColor cyanColor]; view.userInteractionEnabled = YES; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, (44-20)/2, 100, 20)]; label.text = self.array[section]; [view addSubview:label]; //view的tag就等于section 代表点击了哪一个组 view.tag = section; [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(display1:)]]; return view;}- (void)display1:(UITapGestureRecognizer *)g{ //将点击了哪一组转换成字符串 NSString *str = [NSString stringWithFormat:@"%ld",g.view.tag]; //从字典里面以第几组为key取出状态值 //如果状态值为0,代表关闭 if([self.dict[str] integerValue] == 0){ [self.dict setObject:@(1) forKey:str]; } //如果状态值为不为0,代表展开 else{ [self.dict setObject:@(0) forKey:str]; } //记得一定要刷新tabelView,不然没有效果 [self.tabelView reloadData];}- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 44;}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 5;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ /*调用tableView的reloadData方法会重新调用这个方法 从而从字典里面取出相应组对应的状态码,从而判断是需要展开还是收起 */ NSString *str = [NSString stringWithFormat:@"%ld",section]; //将点击了哪一组转换成字符串 if([self.dict[str] integerValue] == 1){ //如果状态值为等于1,代表需要展开返回真正的多少个Cell return 5; }else{ //如果状态值为等于0,代表需要收起返回0 return 0; }}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellId = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if(cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } cell.textLabel.text = @"每一行"; return cell;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}@end
运行效果
我在公司项目做的效果,我感觉后面的箭头还是做的不错的,哈哈,大家可以下载我们应用看看云收益Pro(iOS版本哦)
0 0
- 类似于QQ列表展开和收起的列表
- QQ列表的展开收起
- Android中实现类似qq好友列表展开收起的效果
- Android列表中展开与收起详情
- 类似于qq联系人的tablview能够展开和收缩
- 仿照QQ列表展开效果
- 模拟QQ列表展开收缩
- 类似于微信和QQ消息列表的数字红点,拖拽消失
- UITableView 的展开和 收起
- cell的展开和收起
- QQ列表的收缩展开,带动画效果
- (二十八)QQ好友列表的展开收缩
- JQuery 动画实例:下拉列表框展开收起
- QQ好友列表,点击折叠展开
- 仿QQ列表展开、收缩(1)
- 仿QQ列表展开、收缩(2完善)
- Android ExpandableListView 展开列表控件(手机QQ好友列表)
- 使用listview的展开和收起效果
- Swift - 如何判断一个对象是否是某个类
- 完美解决 iOS 中只旋转自己想要旋转的屏幕
- 一种互联网应用的分布式架构模式微服务应用框架的实现(gradle,dubbo,zookeeper,springmmvc)
- 从log中分析Android wif连接状态的方法
- Android模块化编程——WebView使用之清理缓存
- 类似于QQ列表展开和收起的列表
- Optimized contrast enhancement for real-time image and video dehazing
- Linux学习--初识linux的文件系统以及用户组等概念
- java 支付宝 第三方即时到账支付
- ACM4-1001
- $(document).ready(function(){ }) 的用法解释
- Spring中的Resource接口
- POWERBUILDER -- PB通过URL下载局域网或者互联网上的图片或者文件
- AIDL进程间通讯