【发布时间】:2016-05-21 00:10:54
【问题描述】:
一般情况下,表格的行高是固定的,但根据我的要求,我需要根据其中的内容设置每一行的高度。
谁能给我一些解决方案?
谢谢,
米拉杰
【问题讨论】:
标签: cocoa nstableview
一般情况下,表格的行高是固定的,但根据我的要求,我需要根据其中的内容设置每一行的高度。
谁能给我一些解决方案?
谢谢,
米拉杰
【问题讨论】:
标签: cocoa nstableview
表格视图委托协议有一个tableView:heightOfRow,可让您设置表格视图中每一行的高度。
【讨论】:
感谢大家的建议和帮助。现在使用tableView:heightOfRow:中的以下代码解决了这个问题
float colWidth = [[[tableView tableColumns] objectAtIndex:1]width];
NSString *content = [[[tempArray objectAtIndex:row] objectForKey:@"tValue"] string];
float textWidth = [content sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Lucida Grande" size:15],NSFontAttributeName ,nil]].width;
float newHeight = ceil(textWidth/colWidth);
newHeight = (newHeight * 17) + 13;
if(newHeight < 47){
return 47;
}
return newHeight;
【讨论】: