内细胞高度我用UITableView
显示来自数据库的项目,我已经创建了自定义UITableViewCell
其中有几个标签。我最大的标签是名称说明。
每个单元可以有不同的高度,但我想不出如何设置动态的单元格高度。
我得到的是三个点在标签和高度单元的结束总是约50
如何使基于它里面的标签上单元格高度?
如何设置基础上的UILabel自定义单元格
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *text = _orderProperty.Description;
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE]
constrainedToSize:constraint
lineBreakMode:NSLineBreakByWordWrapping];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
UPDATE
static NSString *CellIdentifier = @"orderDetailCell";
OrderDetailCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
[tableView registerNib:[UINib nibWithNibName:@"OrderDetailCustomCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
OrderProperty* item = [_list objectAtIndex:indexPath.row];
cell.Title.text = item.Title;
NSString* _description = item.Description;
cell.Description.text = _description;
看到此链接的用户 “2014” 回答http://stackoverflow.com/questions/17358322/tableview-convertpoint-fromview-奇怪的行为和解决方法/ 17359673#17359673 –