UITableView的cell 动态 定义 高度
2013-05-10 10:23
218 查看
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
if (indexPath.section==1) {
UITableViewCell *newsCell = [DataTable dequeueReusableCellWithIdentifier:@"newsCell1"];
if (newsCell==nil) {
newsCell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"newsCell1"]autorelease];
}
CGRect cellFrame = [newsCell frame]; //定义的cell 的 frame
cellFrame.origin = CGPointMake(0,0);
UILabel *productLabel31=(UILabel *)[newsCell.contentView viewWithTag:111143];
if (!productLabel31) {
productLabel31=[[UILabel alloc]initWithFrame:CGRectMake(cellXOffset,6,sectionTwoLabelWidth,10)];
productLabel31.backgroundColor=[UIColor clearColor];
productLabel31.tag=111143;
productLabel31.numberOfLines=0;
productLabel31.lineBreakMode=UILineBreakModeWordWrap;
productLabel31.text=[normalTitleArray objectAtIndex:indexPath.section];
productLabel31.font= [UIFont systemFontOfSize:cellProductLabelFont];
CGSize size = [productLabel31.text sizeWithFont:[UIFont systemFontOfSize:cellProductLabelFont] constrainedToSize:CGSizeMake(sectionTwoLabelWidth, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; //算出cell 的具体高度
productLabel31.frame=CGRectMake(cellXOffset,6,sectionTwoLabelWidth,size.height);
[newsCell.contentView addSubview:productLabel31];
[productLabel31 release];
}
cell = newsCell;
cellFrame.size.height = productLabel31.frame.origin.y+productLabel31.frame.size.height +2; // 改变cell 的frame
[cell setFrame: cellFrame]; // 改变cell 的frame
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
UITableViewCell *cell;
if (indexPath.section==1) {
UITableViewCell *newsCell = [DataTable dequeueReusableCellWithIdentifier:@"newsCell1"];
if (newsCell==nil) {
newsCell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"newsCell1"]autorelease];
}
CGRect cellFrame = [newsCell frame]; //定义的cell 的 frame
cellFrame.origin = CGPointMake(0,0);
UILabel *productLabel31=(UILabel *)[newsCell.contentView viewWithTag:111143];
if (!productLabel31) {
productLabel31=[[UILabel alloc]initWithFrame:CGRectMake(cellXOffset,6,sectionTwoLabelWidth,10)];
productLabel31.backgroundColor=[UIColor clearColor];
productLabel31.tag=111143;
productLabel31.numberOfLines=0;
productLabel31.lineBreakMode=UILineBreakModeWordWrap;
productLabel31.text=[normalTitleArray objectAtIndex:indexPath.section];
productLabel31.font= [UIFont systemFontOfSize:cellProductLabelFont];
CGSize size = [productLabel31.text sizeWithFont:[UIFont systemFontOfSize:cellProductLabelFont] constrainedToSize:CGSizeMake(sectionTwoLabelWidth, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; //算出cell 的具体高度
productLabel31.frame=CGRectMake(cellXOffset,6,sectionTwoLabelWidth,size.height);
[newsCell.contentView addSubview:productLabel31];
[productLabel31 release];
}
cell = newsCell;
cellFrame.size.height = productLabel31.frame.origin.y+productLabel31.frame.size.height +2; // 改变cell 的frame
[cell setFrame: cellFrame]; // 改变cell 的frame
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
相关文章推荐
- UITableView的cell 动态 定义 高度
- UITableView性能优化 以及动态计算cell高度 新方法
- 几种设置UITableView的cell动态高度的方法
- 【iOS】UITableView 动态确定cell的高度
- ios-day07-02(模仿新浪微博:UITableView中cell的高度不一致,使用代码来自定义cell、UITableViewController的使用)
- iOS UITableView Cell的动态高度实现
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- UITableView 如何不动态计算返回的cell 的高度
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- [译]使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 总结了几种设置UITableView的cell动态高度的方法
- iOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS开发-UI控件:动态改变UITableView中的Cell高度
- IOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 动态改变UITableView中的Cell高度
- 几种设置UITableView的cell动态高度的方法
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 提升含有动态高度UITableViewCell的UITableView的运行效率
- 动态改变UITableView中的Cell高度