How to set row height based on its contents in a table?

Typically, a table has a fixed row height, but according to my requirements, I need to set the height of each row according to the contents inside it.

Can someone suggest me some solution?

Thanks,

Miraaj

+6
cocoa nstableview
source share
2 answers

Thank you all for your suggestions and help. This problem is now resolved using the 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; 
+1
source share

The table view delegate protocol has tableView: heightOfRow , which allows you to set the height of each row in the table view.

+5
source share

All Articles