博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios中tableview侧栏的折叠
阅读量:7041 次
发布时间:2019-06-28

本文共 3007 字,大约阅读时间需要 10 分钟。

#import "ViewController.h"#define Ksmall 40.0f#define Klarge 80.0f#define KNoOpen @"NoOpen"@interface ViewController (){    int flag;}@property(nonatomic,retain)NSMutableDictionary *mydata;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    self.mydata=[NSMutableDictionary dictionary];    UITableView *tableview=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];    tableview.delegate=self;    tableview.dataSource=self;    [self.view addSubview:tableview];    [tableview release];    // Do any additional setup after loading the view, typically from a nib.}//section-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 5;}//row-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 2;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        NSLog(@"section--》%zi----row--->%zi",indexPath.section,indexPath.row);    static NSString *cellindentify=@"mycell";    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellindentify];    if(cell==nil){        cell=[[[UITableViewCell alloc] init] autorelease];      }    cell.textLabel.text=@"bb";    return cell;}#pragma mark -自定义分组的头部-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 40;}-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    NSLog(@"viewForHeaderInSection");    UIView *view=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)] autorelease];    UILabel *lb=[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100-10, 40)];    lb.text=@"time";       lb.textAlignment=NSTextAlignmentLeft;    [view addSubview:lb];        UILabel *lb1=[[UILabel alloc] initWithFrame:CGRectMake(100, 0, self.view.bounds.size.width-100-10, view.bounds.size.height)];    lb1.textAlignment=NSTextAlignmentRight;    lb1.text=@"right";    [view addSubview:lb1];    return view;}#pragma mark -设置CELL的高度-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{   if(indexPath.row==0){        UITableViewCell *targetCell=[tableView cellForRowAtIndexPath:indexPath];       if(targetCell.frame.size.height==Ksmall+1){
//折叠的情况 [self.mydata setObject:KNoOpen forKey:indexPath]; } else{ [self.mydata removeObjectForKey:indexPath]; } [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row==0){ NSString *isOpen= [self.mydata objectForKey:indexPath]; if ([isOpen isEqualToString:KNoOpen]) { return Klarge; } return Ksmall; } else return Klarge;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}

 

转载地址:http://euhal.baihongyu.com/

你可能感兴趣的文章
UGUI 的多分辨率适配
查看>>
史上最全: svn与git的对照(二):svn与git的相关概念
查看>>
第38周星期六小结
查看>>
一个用于整体移动文件夹的方法,简练实用
查看>>
中国将QFII总额度增至3000亿美元
查看>>
WWDC2016 Session笔记 - iOS 10 UICollectionView新特性
查看>>
[译] 在大型应用中使用 Redux 的五个技巧
查看>>
【译】你不知道的 Chrome 调试工具技巧 第二十一天:Snippets(代码块)
查看>>
css3媒体查询简介
查看>>
Dubbo超时控制源码分析
查看>>
iOS10下使用AutoLayout动画失效解决
查看>>
Dota 2被攻陷!OpenAI 人工智能5V5模式击败人类玩家(4000分水平)
查看>>
Android 性能优化(十二)之我为什么写性能优化
查看>>
软技能-代码之外的生存指南7(精神)
查看>>
Omi 树组件 omi-tree 编写指南
查看>>
Kubernetes 准入控制 Admission Controller 介绍
查看>>
Kotlin协程快速入门
查看>>
AudioKit 入门教程
查看>>
日吞吐万亿,腾讯云时序数据库CTSDB解密
查看>>
02、Python 系列之 Python 环境搭建
查看>>