Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backward compatibility of header height of NSTableView with OS X 10.11

Background:

On OS X 10.11 El Capitan, the default header hight of NSTableView has grown.

Problem:

When I build my NSTableView on OS X El Capitan 10.11 (GM) and Xcode 7.0 (the stable one), the table header hight will be fixed with El Capitan's header hight even on the previous OS versions and so there is a strange unwanted space above the table header (see the screenshots below.)

table header on El Capitan

Fig. 1 Table header on El Capitan (correct)

table header on El Capitan

Fig. 2 Table header on Yosemite (incorrect)

This is of course an undesirable thing.

Question:

How can I avoid this? Is there someone who faces the same issue? I couldn't found even any article in which mentioned about this.

I put my NSTableView using the normal Interface Builder bundled to Xcode 7.0 with Auto Layout enabled.

Update:

I've just confirmed this issue was fixed on Xcode 7.2 + OS X 10.11.2. Now you can modify NSTableView on Interface Builder without worry.

like image 750
1024jp Avatar asked Sep 22 '15 08:09

1024jp


1 Answers

This definitely seems a bug in Apples framework. It only happens when a view is autolayouting. I managed to work around this by subclassing NSTableHeaderView like this:

class TGTableHeaderView: NSTableHeaderView {
    override var frame: NSRect {
        set {
            super.frame = newValue
        }
        get {
            var rv = super.frame
            if #available(OSX 10.11, *) {} else {
                // Correct in versions before El Capitan
                rv.size.height = 17
            }
            return rv
        }
    }
}

And then set this subclass to the header in IB.

like image 169
Marius Avatar answered Oct 11 '22 23:10

Marius