Swift: NSPopUpButtonCell in NSTableHeaderCell

279 views Asked by At

I cannot for the life of my figure out how to get an NSPopUpButtonCell to work in a NSTableHeaderCell. I've tried to implement the solution here: Getting duplicate header button cell in NSTableView when using NSPopUpButtonCell but it seems some of the methods there aren't available in Swift, specifically performClickWithFrame on the headerCell.

I've managed to get the popup button to draw in the header like this:

class DropDownHeaderCell: NSTableHeaderCell {

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override init(textCell aString: String) {
    super.init(textCell: aString)
}

override func drawWithFrame(cellFrame: NSRect, inView controlView: NSView) {
    let buttonCell = NSPopUpButtonCell(textCell: "", pullsDown: true)
    buttonCell.addItemsWithTitles(["Item1", "Item2", "Item3"])
    buttonCell.drawWithFrame(cellFrame, inView: controlView)
}   
}

Whenever I try to click on the button it selects the header cell instead. How do I get it so that my click register on the button and not the header?

0

There are 0 answers