0

i have a outline view with a custom cell. all works fine but i need to know, if a button was pressed, in which row number the that button is.

how can i get this row number ?

Trombone0904
  • 4,132
  • 8
  • 51
  • 104
  • You can find it here, Hope this helps. http://stackoverflow.com/questions/28659845/swift-how-to-get-the-indexpath-row-when-a-button-in-a-cell-is-tapped – Aaqib Hussain May 21 '17 at 10:02
  • sry, perhaps i have to say that i use a nsoutlineview instead of a tableview (my mistake) and that i programming for OS X, not for iOS – Trombone0904 May 21 '17 at 10:17

1 Answers1

0

You could wire up your button's action to an IBAction in your view controller (or whatever knows about the outline view) and call row(for:) on the outline view:

@IBAction func buttonClicked(_ sender: NSButton) {
    print("button row:", outlineView.row(for: sender))
}

Straight from the docs:

This method is typically called in the action method for an NSButton (or NSControl) to find out what row (and column) the action should be performed on.

thm
  • 1,217
  • 10
  • 12
  • but i can't create an IBAction of my button in the view controller class, because my butte is assign to the custom cell class – Trombone0904 May 22 '17 at 06:23
  • What do you mean you can't? You can send the action to any object. Or are you creating your interface in code and the custom cell doesn't know about the outline view? In any case, please note that you can send actions to the first responder (by setting target to nil in code or by connecting to "First Responder" in Interface Builder). – thm May 22 '17 at 08:53