NSStepper in NSTableCellView does not affect

I use a regular (not subclass) NSTableCellView in a table view based view. It has initial images and text fields. I added NSStepper to the view.

The text field is bound to tableCellView.objectValue.quantity. The value of steppers is also bound to tableCellView.objectValue.quantity.

The problem is that when I start the application, when I click on the pedometer, it does not seem to receive a mouse event, no arrow is highlighted, the value does not increase or decrease.

If I set the double action of the table view, it starts if I double-click on the pedometer, as if it were transparent.

What am I missing?

Thanks!

+7
source share
2 answers

You should look at the documentation, but the simplest thing is that you need to subclass NSTableView and override this method to verify the proposed first responder. Because the document states that NSTableViews prohibits the use of certain controls, unless the first one is selected. Even then, he can still give up some.

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

In addition to Robert Payne's correct answer using Swift, you can add an extension to NSTableView, not a subclass.

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

And I would like to emphasize that this is an NSTableView, not an NSTableViewCell.

0
source

All Articles