Pregunta

I’m using a regular (not subclassed) NSTableCellView in a view-based table view. It has the initial image and text field views. I added an NSStepper to the view.

The text field is bound to tableCellView.objectValue.quantity. The stepper’s value is bound to tableCellView.objectValue.quantity too.

The problem is that when running the app, when I click the stepper it doesn’t seem to get the mouse event, neither arrow gets highlighted, the value is not incremented or decremented.

If I set the double action of the table view it gets triggered if I double-click the stepper as if it was transparent.

What am I missing?

Thanks!

¿Fue útil?

Solución

You should look at the documentation but easiest is that you need to subclass NSTableView and override this method to validate the proposed first responder. As the document states NSTableViews disallow some controls to be used unless the row is first selected. Even then it still may discard some.

- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {
    return YES;
}

Otros consejos

Further to the correct answer from Robert Payne, with Swift you could add an extension to NSTableView and not subclass it.

extension NSTableView {
    override public func validateProposedFirstResponder(responder: NSResponder, forEvent event: NSEvent?) -> Bool {
        return true
    }
}

And I'd like to emphasis that it's the NSTableView not the NSTableViewCell.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top