Getting the column and row of an NSCell in an NSMatrix in Cocoa

894 views Asked by At

Given an NSMatrix and an NSCell is there a quick way to query the matrix to know at which row and column in the matrix the cell is placed. I would like to know this upon receiving action messages from NSActionCells.

The only way I can see of doing it is to loop through the rows and columns of the matrix and check for equality with the message sender, or give tags to the cells based on their position, which is ugly. I'm sure there's a better way of doing this, isn't there?

2

There are 2 answers

1
Peter Hosey On BEST ANSWER
0
NSResponder On

I think you should set a -tag value on the cells in question. The canonical example of this is the cells in a matrix of digits for a calculator app. Instead of trying to figure out where they are in the matrix, you can just check their tag to see what digit they represent.