1

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?

phimuemue
  • 34,669
  • 9
  • 84
  • 115

1 Answers1

2

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.

phimuemue
  • 34,669
  • 9
  • 84
  • 115
Marc T.
  • 5,090
  • 1
  • 23
  • 40
  • I think you are right that I need to implement `drawInterior` in my derived class. How did you find out about this? Trial-and-error? Can you point me to some documentation? – phimuemue Jul 05 '18 at 16:01
  • @phimuemue Intuitively, I am programming Cocoa now for over 10 years :-) – Marc T. Jul 06 '18 at 04:56
  • @Mark T Thank you. Slightly off-topic: I still find it uncommon to check whether a derived class implements `MethodA` to decide whether we call `MethodB`. Do you know other examples where Cocoa does that kind of check? – phimuemue Jul 09 '18 at 08:39
  • @phimuemue I don't remember exactly when I got the problems but many times it was related to Controls, drawing and events. – Marc T. Jul 10 '18 at 06:38