0

So, is the button identifiable?

I need to identify a cell-botton (Button Cell) in aNSTableView in order to detect if it was pressed already. The table can always change by user input. My bright idea is if a created button (button cell) were unique it would be identifiable. Is that possible?

JFS
  • 2,992
  • 3
  • 37
  • 48

2 Answers2

1

Well, as long as these buttons are subclasses of UIView, which UIButtons are, then you can use the tag field to carry a numeric information. Set the button.tag in celForRowAtIndexPath to indexPath.row and you can fetch the tag within the IBAction method that the button should inovke when pressed.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • Hallo Hermann, danke for the answer. The cell buttons are subclasses of `NSButtonCell` class (it's for osx). Would you have a code snippet how to use the `cellForRowAtIndexPath` to create the tag? – JFS Mar 11 '13 at 20:24
  • Apologies. I overlooked that it was related to the OS-X framework. Obviously I did not really read it and thought it was related to iOS. No, I cannot help with OS-X. – Hermann Klecker Mar 11 '13 at 20:38
  • Glad you got an answer. Tschüs :) – Hermann Klecker Mar 11 '13 at 21:06
1

Cells are a little different from full-fledged controls. NSTableView reuses a single cell for all the rows of a column. When NSTableView draws a row, or when it handles user input, it configures the cell for the row/column in question.

It sounds like in your case you have an NSButtonCell and you want to know which row was clicked. You can determine which row was clicked by checking the table view's clickedRow property in the button cell's action method. The answer to this question explains how to do this.

Community
  • 1
  • 1
Alex
  • 26,829
  • 3
  • 55
  • 74
  • Yes it is an `NSButtonCell`. The `clickedRow` method work for me. But am I right that the number of a specific row will change with deleting/adding rows above? – JFS Mar 11 '13 at 20:50
  • That's correct. What I would do is go back to the table's data source and use the row index to fetch the object that the row represents. That should give you the data you need to handle the button click. – Alex Mar 11 '13 at 21:01