Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Generally, table has a fixed row height but according to my requirements I need to set height of each row according to content within it.

Can anyone suggest me some solution for it?

Thanks,

Miraaj

like image 797
Devarshi Avatar asked Jul 05 '10 15:07

Devarshi


2 Answers

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

like image 197
dj2 Avatar answered Oct 12 '22 23:10

dj2


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;
like image 39
Devarshi Avatar answered Oct 12 '22 23:10

Devarshi