The explanation for the both clickedRow and selectedRow is like this :
Returns the index of the row the user clicked to trigger an action message.
Returns the index of the last row selected or added to the selection.
From this description, it is not clear what they actually mean. What is “selected” and what is “clicked”?
Isn’t a selected row a clicked row? What is the difference between “clicked” and “selected”?
It turned out that there is subtle difference.
Again, Seeing once is much much better than explaining 100 times in words.
The row in solid blue is “selected” row, while the row of which outline is only blue is “clicked” row.
Then, how to select and click?
For selecting, you click the row using a left button, or if you have a single-button mouse, then click the button.
For clicking, you click the row using a right button, or if you have a single-button mouse, click the button with control key pressed.
Why is this necessary? Isn’t “selected” only necessary?
No, let’s consider this case. You attach a contextual menu to an NSTableView.
On a row, you left-clicked a row, and on the other row you right-clicked it to bring a contextual menu.
Then in a menu handler for the contextual menu, you want to manipulate an item you selected.
Now, it matters what “selected” means here. The Mac OS X doesn’t change the item selected when it handles right-clicking.
So, the “clickedRow” returns index for the row of which outline is drawn in solid blue.
There are scenarios :
- clickedRow == selectedRow
- clickedRow == -1 and selectedRow >= 0
- clickedRow >=0 and selectedRow >= 0 and (clickedRow != selectedRow )
- clickedRow < 0 and selectedRow < 0
The case 2 is when a user selected a row, and brings a information dialog like shown above using a hot-key.