Weird rectangle (NSBannerView) in left top of NSTableView

断了今生、忘了曾经 提交于 2019-12-13 13:42:30

问题


I'm working on an macOS app and I'm experiencing a weird issue. In the left top corner of my NSTableView (above the header), a grey rectangle is shown:

(I've added an NSBox behind the NSTableView to make it more clear in the screenshot)

With the Debug View Hierarchy, I've seen it's an NSBannerView which is added to the Scroll View wrapping the Table View.

My UI is built with Interface Builder (a storyboard). I've checked and unchecked lots of checkboxes in the Interface Builder but can't find what it is. Google and Stack Overflow also don't give any clues. Googling for "NSBannerView" even only yields some macOS header files.

How to get rid of the rectangle?

Environment details

  • macOS Mojave 10.14 Beta (18A365a)
  • Xcode 9.4.1 (9F2000)

回答1:


Subclass NSTableRowView and overwrite layout, where you hide the view

- (void)layout {

    [super layout];

    for (NSView * v in self.subviews) {
        if ([v.className isEqual:@"NSBannerView"]) {
            v.hidden = YES;
        }
    }

}



回答2:


Making this hiding thing into didAddSubview might be a better solution like the example below. Because layout is called each time you select the row.

override func didAddSubview(_ subview: NSView) {
    super.didAddSubview(subview)

    if subview.className == "NSBannerView" {
        subview.isHidden = true
    }
}


来源:https://stackoverflow.com/questions/52153244/weird-rectangle-nsbannerview-in-left-top-of-nstableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!