Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind click action of NSButton in view based NSTableView

I have an NSTableView that is set to be 'view based', and within each NSTableCellView there is an NSButton and an NSTextField.

The text field is being populated correctly from an array controller. The buttons are appearing correctly but I'm having trouble working out how to hook up the click action.

I thought this would be possible by control-dragging from the NSButton in IB to a simple method like this one in my controller (in this case an NSDocument subclass):

- (IBAction)testAction:(NSButton *)sender {
    NSLog(@"Test action");
}

It connects fine but never gets fired. Any ideas why this is or how to fix it?

like image 219
Mark Wheeler Avatar asked Dec 26 '13 10:12

Mark Wheeler


1 Answers

I don't understand why this works, but I had the same problem and was able to get it working by assigning the table delegate and datasource to the file owner within IB, which is also the class of my click handlers. Only then did it seem to actually bind the click handlers for the buttons in my cell view. Previously I was setting the delegate and datasource in code after the view was loaded.

like image 175
len Avatar answered Oct 21 '22 17:10

len