NSPopUpButton: NSPopUpButtonCell deprecated?

580 Views Asked by At

The documentation for NSPopUpButton states:

An NSPopUpButton object uses an NSPopUpButtonCell object to implement its user interface.

I derived a new class from NSPopUpButtonCell which implements drawBorderAndBackgroundWithFrame:inView: to achieve custom drawing. In addition, I derived a new class from NSPopUpButton and use cellClass to use my derived class for it. (i.e. I am not working via interface builder.)

With the advent of macOS 10.14 beta however, this routine is not called anymore, and I observe the "normal" (i.e. non-customized) drawing.

Thanks to @Marc T.'s answer, I (think I) was able to localize the problem to the fact that the cell apparently calls drawBorderAndBackgroundWithFrame:inView: only if drawInteriorWithFrame:inView: is implemented in the derived cell.

I could not find solid documentation on this. Is there any?

1

There are 1 best solutions below

4
Marc T. On BEST ANSWER

If there would be such a change in macOS 10.14 I assume Apple would have announced this on WWDC 2018. A quick check in Interface Builder showed me that nothing has changed so far. Creating a subclass of NSPopUpButtonCell to use it as the class for the popup button cell is still working as expected. What I have to mention is that drawBorderAndBackground is only called if drawInterior is implemented as well. Since I was never using drawBorderAndBackground before, I can not say if this is a change from previous versions to 10.14 or not.

class Cell: NSPopUpButtonCell {

override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
    super.drawInterior(withFrame: cellFrame, in: controlView)
    print("drawInterior")
}

override func drawBorderAndBackground(withFrame cellFrame: NSRect, in controlView: NSView) {
    super.drawBorderAndBackground(withFrame: cellFrame, in: controlView)
    print("drawBorderAndBackground")
}
}

Hope this helps.