Search code examples
macosautolayoutnstableviewnstablecellview

NSTableView redrawn too often when using auto layout


Every times I change the value of my NSTextfield, the entire tableView (view based) is redrawn.

It's probably due to the intrinsicContentSize that may change.

I tried this, but nothing did change

- (NSSize)intrinsicContentSize
{
    return NSMakeSize(NSViewNoInstrinsicMetric,NSViewNoInstrinsicMetric);
}

TableView size Style is set to Custom width a fixed row Height.

TexField's constraints are

V:|-20-[myTextField(14)]

H:|-20-[myTextField(50)]

I also tried to don't call super in

invalidateIntrinsicContentSize
and 
invalidateIntrinsicContentSizeForCell:(NSCell *)cell

and tried to manually set setNeedsLayout to NO

- (void) setObjectValue:(id)objectValue
{
    [super setObjectValue:objectValue];
    [self setNeedsLayout:NO];
    [self setNeedsUpdateConstraints:NO];    
}

And the tableView is still redrawn...

What do I have to do to avoid this ?


Solution

  • I was using Quartz Debug with "flash screen updates" enabled to see the parts of the screen being redraw, and the entire tableView was flashing.

    After overriding the drawRect of the tableview and the textfield, I saw that the dirty rect and the Quartz flashing Rect were not the same. TableView is not entirely redraw.