实现的功能:点击cell显示cell的详细信息,再次点击关闭cell的详细信息。
#import <UIKit/UIKit.h>
@interface MyCell : UITableViewCell{ UILabel *lab_info; UILabel *lab_detailInfo; CGFloat normalHeight;}@property (retain,nonatomic)UILabel *lab_info,*lab_detailInfo;@property CGFloat normalHeight;-(CGFloat)getMyCellHeight;-(void)resetCellHeight;
@end
#import "MyCell.h"
@interface MyCell()
{
}
@end
@implementation MyCell
@synthesize lab_info,lab_detailInfo;
@synthesize normalHeight;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
lab_info=[[UILabel alloc]init];
[self.contentView addSubview:lab_info];
//
self.normalHeight=self.frame.size.height;
//
lab_detailInfo=[[UILabel alloc]init];
lab_detailInfo.lineBreakMode=NSLineBreakByCharWrapping;
lab_detailInfo.numberOfLines=5;
[self.contentView addSubview:lab_detailInfo];
//
self.layer.shadowColor=[UIColor blackColor].CGColor;
self.layer.shadowOffset=CGSizeMake(0, 2);
self.layer.shadowOpacity=0.3;
self.layer.shadowRadius=2;
//
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
-(CGFloat)getDetailLabViewHeight
{
[self.lab_detailInfo sizeToFit];
return self.lab_detailInfo.frame.size.height;;
}
-(CGFloat)getMyCellHeight
{
return normalHeight +[self getDetailLabViewHeight];
}
-(void)resetCellHeight
{
[self layoutIfNeeded];
CGRect cellFrame=self.frame;
cellFrame.size.height=normalHeight+[self getDetailLabViewHeight];
[self setFrame:cellFrame];
}
-(void)layoutSubviews
{
[super layoutSubviews];
//设置标题的lab的高度
CGRect lab_info_Frame=CGRectInset(self.frame, 0, 0);
lab_info_Frame.origin.x=lab_info_Frame.origin.y=0;
lab_info_Frame.size.height=normalHeight;
[lab_info setFrame:lab_info_Frame];
//设置详细信息的高度
CGRect lab_detailInfo_Frame=CGRectInset(self.frame, 0, 0);
lab_detailInfo_Frame.origin.x=0;
lab_detailInfo_Frame.origin.y=normalHeight;
lab_detailInfo_Frame.size.height=[self getDetailLabViewHeight];
[lab_detailInfo setFrame:lab_detailInfo_Frame];
//
//[self setNeedsDisplay];
}
-(void)drawRect:(CGRect)rect
{
[super drawRect:rect];
self.contentView.backgroundColor=[UIColor grayColor];
lab_info.backgroundColor=[UIColor clearColor];
lab_detailInfo.backgroundColor=[UIColor clearColor];
}
@end
#import <UIKit/UIKit.h>
#import "MyCell.h"
@interface RootViewController : UITableViewController
{
NSMutableArray *isItemSelected;
}
@end
#import "RootViewController.h"
@implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
isItemSelected=[[NSMutableArray alloc]initWithCapacity:5];
for (int i=0; i<5; i++)
{
[isItemSelected insertObject:[NSNumber numberWithBool:NO] atIndex:i];
}
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = (MyCell*)[[MyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
cell.lab_info.text=[NSString stringWithFormat:@"title-%d",indexPath.row];
cell.lab_detailInfo.text=[NSString stringWithFormat:@"subtitle-%d",indexPath.row];
if ([[isItemSelected objectAtIndex:indexPath.row]boolValue]==YES) {
cell.lab_detailInfo.hidden=NO;
}else{
cell.lab_detailInfo.hidden=YES;
}
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell=(MyCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
if ([[isItemSelected objectAtIndex:indexPath.row] boolValue]==YES) {
return [cell getMyCellHeight];
}
else
{
return cell.normalHeight;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BOOL b=[[isItemSelected objectAtIndex:indexPath.row]boolValue];
[isItemSelected replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithBool:!b]];
//
[tableView reloadData];
// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
效果是这样的
分享到:
相关推荐
这一个小Demo简单的实现了点击cell,在cell下面又可以延伸出无数的cell,感兴趣的朋友可以实现一下无线延伸
tableview抽屉,点击cell弹出n个子cell,依次类推,支持cell行高自适应。。。一个不一样的思路
点击button动态的添加一个cell,解决了一些小问题分享给大家!
Cell组件(Activex 控件,扩展名为OCX)主要适用于开发windows应用程序,是为商业软件解决实际开发过程中的图表、报表显示,输入,打印输出等问题的最理想的解决方案。可在VC, VB, Delphi, PB,VFP,C++ Builder等...
将cell类型的数据转换为double类型的函数
Cell组件(Activex 控件,扩展名为OCX)主要适用于开发windows应用程序,是为商业软件解决实际开发过程中的图表、报表显示,输入,打印输出等问题的最理想的解决方案。可在VC, VB, Delphi, PB,VFP,C++ Builder等...
点击展开cell
cell开发文档,非常有用的cell表格开发api,适用于表格类开发人员
半年ios 学习的菜鸟 制作滑动cell置顶(用了一个比较鸡贼的办法,想知道的可以看层级视图)点击cell 选择隐藏cell的下拉框 但是没有解决cell上button的复用问题,哪位大神会的帮忙修改下谢谢
通过控制cell的高度来实现折叠展,因为cell的折叠展开有多种方法,这个应该是最简单的一种。难登大雅之堂,各位coder不要见笑。。。后续会上传其他几种cell的折叠展开方法。。。当然时间不确定。。。
UITableView在两个Cell中间显示目录效果,点击列表某一项,在该项下面显示菜单,不挡住下一项,很实用的例子。
cell点击下拉
2.实现了可删除的tableViewCell,向左划动某个cell,cell右侧会出现“删除”按钮,点击即可将当前cell删除,删除伴有简单的动画效果。 3.实现了tableView的下拉刷新功能,下拉tableView的过程中,将依次显示“下拉...
一TICLI 中的命令(其中[;ucl]可加可不加)) ...init:cell X:spp as init:cell X:spp rms inh:cell,flash,extern 5. 看基站里CRC中的软件 MD/CP站:op:cell X,cdm Y,generic CDBS(MM)站:op:cell X,bbu 1,generic
cell帮助手册 华表cell中文帮助手册
半年ios 学习的菜鸟 制作滑动cell置顶(用了一个比较鸡贼的办法,想知道的可以看层级视图)点击cell 选择隐藏cell的下拉框 更新了button复用的问题,但是上拉置顶的点击同步。暂时未做,看层级试图的话可以看出...
根据网上以为的点击cell下拉内容展开,经过本人的修改符合自己demo的需求;主要是通过点击cell刷新改变cell的高度来显示cell下面label的内容,适合新手学习,大神勿喷!
thinkcell 的有效期只有15天,每隔15天就要找一次码太麻烦了,有了这个程序加上python,就可以自动跳过thinkcell的有效期限制啦
用友华表的CELL插件是一款基于ActiveX技术的解决中国式报表显示和打印的第三方控件, 和其它第三方ActiveX控件一样,用友华表CELL插件只能运行在客户端,只能使用JAVASCRIPT、VBSCRIPT客户端语言操纵控件,进行直接...
cell即将显示时实现动画效果