How to set row height based on its content in table?

爱⌒轻易说出口 提交于 2019-12-05 06:52:36

The table view delegate protocol has a tableView:heightOfRow that lets you set the height of each row in the table view.

Devarshi

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!