NSTableView and variable row height with core data
NSTableView and variable row height with core data
- Subject: NSTableView and variable row height with core data
- From: Ross Winn <email@hidden>
- Date: Tue, 2 Aug 2005 20:06:00 -0700
I have a NSTableView that is being populated by a NSArrayController
getting it's information from core data. So far so good. I have been
trying get the row heights to change depending on the length of the
string as it wraps. I am using sizeWithAttributes to get the length
of the string which I am dividing by the length of the column; round
up with a little ceil() magic and multiply by 17.0 (the height I want
each row to be) and presto-change-o it doesn't work.
The problem is that the size of the attributed string is coming out
to be much less than it should. So the wrapping seldom occurs exactly
where it needs to be. Does anyone know a way around this or am I
using the wrong methods to get this job done. I'm still kind of new
at cocoa so I wouldn't doubt it.
Here is an example of the code I am using...
- (float)tableView:(NSTableView *)tableView heightOfRow:(int)row
{
NSTableColumn *col = [[MyTableView tableColumns] objectAtIndex:1];
float colWidth = [col width];
// making sure I'm using the right font
// NSLog(@"font: %@", [[col dataCellForRow:row] font]);
NSString *content = [[[MyArrayController arrangedObjects]
objectAtIndex:row] valueForKey:@"content"];
float textWidth = [content sizeWithAttributes:[NSDictionary
dictionaryWithObject:[NSFont fontWithName:@"LucidaGrande" size:13.00]
forKey:@"NSFontAttributeName"]].width;
float newHeight = ceil(textWidth/colWidth);
// Checking to see the sizes of everything involved
NSLog(@"textWidth: %f, colWidth: %f, newHeight: %f", textWidth,
colWidth, newHeight);
newHeight = newHeight * 17.0;
return newHeight;
}
Any suggestions would be greatly appreciated.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden