如何在 iOS 应用程序中使用 TdBadgedCell 动态管理高度单元?
我已经在我的 iOS ap 中实现了一些 TdBadgedCell (来自 https://github.com/tmdvs/TDBadgedCell) 在 UITabView 中。但是,当我想通过使用类似以下示例的内容动态管理单元格的高度时:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
单元格的宽度是单元格的整个宽度(下例中计算的变量“约束”),而不是屏幕上打印的标签的实际宽度考虑徽章的宽度。因此,当文本太长时,UILabel 末尾的文本部分不会出现在单元格中。
请问我该如何解决这个问题?
i've implemented, in my iOS ap, some TdBadgedCell (from https://github.com/tmdvs/TDBadgedCell) in a UITabView. But when I want to manage the cells' hight dynamically by using something like this example:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN * 2);
}
the cell's width is the entire width of the cell (calculated variable "constraint" in the example below) and not the real width of the label printed on screen taking consideration of the badge's width. So, the portion of text at the end of the UILabel doesn't appear in cell when the text in too long.
How can I resolve this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我已经用这部分代码解决了我自己的问题:
I've solved my own problem with this portions of code: