Difference between clickedRow and selectedRow of NSTableView

The explanation for the both clickedRow and selectedRow is like this :

clickedRow

Returns the index of the row the user clicked to trigger an action message.

selectedRow

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.
difference-betwen-selectedrow-and-clickedrow
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 :

  1. clickedRow == selectedRow
  2. clickedRow == -1 and selectedRow >= 0
  3. clickedRow >=0 and selectedRow >= 0 and (clickedRow != selectedRow )
  4. 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.

One response to this post.

  1. Greatings,
    Ugh, I liked! So clear and positively.

    Have a nice day
    AlexAxe

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: