Edward Loveall
Edward Loveall

Reputation: 2253

NSTableView triggering another action when clicked

While learning objective-c, I've made a basic mac shopping list app with 3 interface elements: NSTextField, NSButton and NSTableView. The basic idea is you type something into the text field, hit the add button (or hit return) and it adds it to the table view. Everything works as expected until I click on the table view at which point it adds what ever is currently to the text field to the table view.

The only action I have is addItem which adds the text field's stringValue to NSTableView's data source, an NSMutableArray. I've set it to be only triggered by the button and the textfield, not the NSTableView. When I remove the action from NSTextField the problem stops. Any suggestions?

Upvotes: 2

Views: 530

Answers (1)

Nate Thorn
Nate Thorn

Reputation: 2183

The NSTextField fires its action both when the user hits the Enter key and when it loses focus. When you click on the NSTableView, the NSTextField loses focus, so it calls its action.

If you only want it to send its action on Enter, there is a pop up button in the NSTextField's attributes tab labeled "Action" that you can set to "Sent on Enter Only".

Upvotes: 3

Related Questions