tableview动态算一次高度的方法
来源:互联网 发布:java电商项目简历 编辑:程序博客网 时间:2024/05/16 04:26
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section % 2 == 0) {
static XLNShoppingCartTitleCell *cell = nil;
static dispatch_once_t onceToken;
//只会走一次
dispatch_once(&onceToken, ^{
cell = (XLNShoppingCartTitleCell *)[tableView dequeueReusableCellWithIdentifier:@"XLNShoppingCartTitleCell"];
});
CGFloat height = [cell calulateHeightWithtTitle:[self.dataSourceArray objectAtIndex:indexPath.section] desrip:[self.dataSourceArray objectAtIndex:indexPath.section]];
return height;
} else {
static XLNShoppingCTableViewCell *cell = nil;
static dispatch_once_t onceToken;
//只会走一次
dispatch_once(&onceToken, ^{
cell = (XLNShoppingCTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"XLNShoppingCTableViewCell"];
});
CGFloat height = [cell calulateHeightWithtTitle:[self.dataSourceArray objectAtIndex:indexPath.section] desrip:[self.dataSourceArray objectAtIndex:indexPath.section]];
return height;
}
}
{
if (indexPath.section % 2 == 0) {
static XLNShoppingCartTitleCell *cell = nil;
static dispatch_once_t onceToken;
//只会走一次
dispatch_once(&onceToken, ^{
cell = (XLNShoppingCartTitleCell *)[tableView dequeueReusableCellWithIdentifier:@"XLNShoppingCartTitleCell"];
});
CGFloat height = [cell calulateHeightWithtTitle:[self.dataSourceArray objectAtIndex:indexPath.section] desrip:[self.dataSourceArray objectAtIndex:indexPath.section]];
return height;
} else {
static XLNShoppingCTableViewCell *cell = nil;
static dispatch_once_t onceToken;
//只会走一次
dispatch_once(&onceToken, ^{
cell = (XLNShoppingCTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"XLNShoppingCTableViewCell"];
});
CGFloat height = [cell calulateHeightWithtTitle:[self.dataSourceArray objectAtIndex:indexPath.section] desrip:[self.dataSourceArray objectAtIndex:indexPath.section]];
return height;
}
}
- (CGFloat)calulateHeightWithtTitle:(NSString*)title desrip:(NSString*)descrip
{
//这里非常重要
CGFloat preMaxWaith = [UIScreen mainScreen].bounds.size.width - 60;
[self.detailLabel setPreferredMaxLayoutWidth:preMaxWaith];
[self.titleLabel setText:title];
//这也很重要
[self.detailLabel layoutIfNeeded];
[self.detailLabel setText:descrip];
[self.contentView layoutIfNeeded];
CGSize size = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
//加1是关键
return size.height+1.0f;
}
0 0
- tableview动态算一次高度的方法
- 动态改变tableview的cell的高度
- 动态设置TableView加载完毕后TableView的高度
- iOS tableview动态高度
- 关于tableview高度自适应的一个方法
- iOS 设置tableview动态高度
- IOS tableView cell动态高度 (autoLayout)
- MVVM动态计算Cell套TableView高度
- tableView 的cell自适应高度
- autolayout 计算tableView的高度
- tableView 头视图的高度
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- 动态调整UITableViewCell高度的实现方法
- Bad horse(图的广度遍历解法)
- 智能指针auto_ptr源码
- 如何用Cocoapods创建一个开源库
- VMware安装linux虚拟系统如何链接外网?
- C++_编写动态链接库
- tableview动态算一次高度的方法
- hdu(1069)——Monkey and Banana(LIS变形)
- zedboard 开启rz sz串口命令支持
- Interleaving String(*****)
- hdu 1142 A Walk Through the Forest(最短路)
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
- 黑马程序员——集合框架类(Collections、Arrays)
- uva 1343 IDA*
- leetcode-110:判断平衡二叉树 Java