• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTableView row heights with auto layout and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView row heights with auto layout and bindings


  • Subject: NSTableView row heights with auto layout and bindings
  • From: Jonathan Guy <email@hidden>
  • Date: Tue, 30 Jun 2015 17:56:00 +0100

Hi
Im trying to fix a problem with dynamic row heights with auto layout and bindings which was working fine in an older build of Xcode but which now no longer works. So my new attempt for the most part works but about 30% of my row heights are not correctly calculated. Basically I create a reference NSTableCellView, set my model object as the objectValue which then updates the bindings, set the frame width of the reference cell to the column width then work out the height from there by setting preferredMaxLayoutWidth on the wrapping text field. Here's the code to do the calculation


1	- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
2	{
3	    static NSTableCellView *cellView = nil;
4
5	    if (cellView == nil) {
6	        NSDictionary *nibs = [tableView registeredNibsByIdentifier];
7	        NSNib *nib = nibs[@"MainCellView"];
8	        NSArray *topLevelObjects = nil;
9
10	        [nib instantiateWithOwner:nil topLevelObjects:&topLevelObjects];
11
12	        for (id object in topLevelObjects) {
13	            if ([object isKindOfClass:[NSTableCellView class]]) {
14	                cellView = object;
15	                break;
16	            }
17	        }
18	    }
19
20	    LogEntryNode *node = self.logEntryNodes[row];
21
22	    cellView.objectValue = node;
23
24	    NSTableColumn *tc = tableView.tableColumns[0];
25	    NSSize size = NSMakeSize(tc.width, 43.0);
26
27	    [cellView setFrameSize:size];
28	    [cellView setNeedsLayout:YES];
29	    [cellView layoutSubtreeIfNeeded];
30
31	    cellView.textField.preferredMaxLayoutWidth = cellView.textField.frame.size.width;
32
33	    CGFloat height = cellView.textField.intrinsicContentSize.height;
34	    CGFloat padding = cellView.frame.size.height - cellView.textField.frame.size.height;
35
36	    height += padding;
37
38	    return (height < 43.0) ? 43.0 : height;
39	}

This seems to be the way Corbin Dunn recommends but that was without using auto layout. The calculated heights are usually out by anything from 2 to 5 rows of text. Has anyone had any success doing it this way? Is there something I'm missing? Any help would be appreciated.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Prev by Date: Re: Cheating a synchronous call on the main thread
  • Next by Date: Re: Cheating a synchronous call on the main thread
  • Previous by thread: Re: UIPageViewController not resizing its child view controllers on rotation
  • Next by thread: UITextFieldDelegate
  • Index(es):
    • Date
    • Thread