且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何根据表中的内容设置行高?

更新时间:2023-01-24 22:41:50

感谢您的建议和帮助。现在使用 tableView中的以下代码解决此问题:heightOfRow:

Thanks all for your suggestions and help. This problem is now resolved using following code in 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;