NSTextView substructure does not display when drawsBackground = false

  • Add an NSTextView (either manually or through the interface builder).
  • Set drawsBackground = false
  • Add subview directly to NSTextView

Subview will not be visible.

However, if I add another subtitle to the same level as, for example, NSScrollView, the first preview will appear.

Here is an example project for Xcode: https://www.dropbox.com/s/inz30bq9xzdw0g5/TestTextSubviews.zip?dl=0

In the source code, if you uncomment the following lines:

// let bg2 = BgView (frame: NSRect (x: 105, y: 105, width: 100, height: 100)) //window.contentView.addSubview(bg2)

then the add-in will first appear.

+5
source share
1 answer

I do not know the exact reason, but I suspect that this is a problem in the hierarchy of representations. I created a new project from the cocoa application template, added nstextview, and then added 1 and then 2 of your subviews - it seems to work as intended. Setting up a cocoa application template with a window controller and a view controller, so perhaps this correctly sorts the strangeness of the hierarchy view, which is not obvious from directly adding the view to the window in nib. Here is an example project - https://www.dropbox.com/s/sef54sc2pgdws7f/NSTextViewAddSubviews.zip?dl=0

(NB: I'm on Xcode 7 beta right now, but I don't think this should matter)

0
source

All Articles