About | Buy | Forum | Industry Watch | Learning Curve | Products | Search | Twitter | Xnews
Home » Learning Curve » Developers Workshop

NSTableView Revisited

There's something really wrong with this control.


Buy It

Try It

Perhaps a story in pictures will make it easier to understand. Especially for those who are saddled with the task of fixing the code.

Take any Cocoa app that's document based. Serve up a directory where several files used by the app are found. Invoke the application's 'open' dialog (⌘O).

The 'open' dialog admits of three views for browsing.

  1. A 'big icon' (Finder) view.
  2. An 'outline' view (NSOutlineView).
  3. A browsing view (NSBrowser).

It's important to understand how the NSBrowser and NSOutlineView classes are related: they're not. They're two entirely separate beasts. But NSOutlineView inherits directly from NSTableView and it's NSTableView that's the culprit. So using a Cocoa 'open' dialog is a perfect opportunity to see how this table view class screws up in Leopard.

It's also important to point out yet again that this weird behaviour did not occur prior to Leopard. In fact as this is a 'standard operating procedure' 'across the board' on all platforms and may have originated on the original Mac it's probably fair to state it's never occurred anywhere before now.

You can also test this with ordinary text. Follow along and use the form below.

1. Use a shift key, your arrow keys, and your cursor to select the middle sentence.

2. Without disturbing the selection you've made hold down shift and click right before the first word in the text.

3. Without disturbing the selection you've made hold down shift and click right after the last word in the text.

Everything gets selected.

Why does that work? Several reasons.

  1. 'Shift' is the 'selection' key. Wherever you move your 'caret' the selection will follow if you're holding down shift.
  2. The control remembers where you last moved your 'caret'. [This directly corresponds to a 'selected row' in either NSBrowser or NSOutlineView (or NSTableView).]

And the same applies for other controls. Such as NSBrowser, NSOutlineView, and NSTableView. Or at least it should. Or at least it always has on any platform of your choosing. It's a standard behavioural rule and it's also been with the Cocoa classes for over twenty years.

Until now. Until something got royally messed up in Leopard.

So let's see how Leopard performs - let's compare the above text behaviour with NSBrowser and finally with NSOutlineView (and thereby with NSTableView, the real culprit).

1. 'Correct Behaviour'

This first part illustrates how the NSBrowser class behaves - this is 'correct behaviour'.

1. Go to a 'good' directory with lots of available files. Select a file in the middle of the column.

2. Hold down shift and click on the file at the top of the column.

3. Hold down shift and click on the file at the bottom of the column.

Everything gets selected. [This is NSBrowser. This isn't the screwed up class. NSOutlineView is (along with NSTableView).]

Now try the same experiment again - but first click in the upper left of the dialog to get the 'outline' view.

2. 'Incorrect Behaviour'

This second part illustrates how the NSOutlineView and NSTableView classes for Leopard behave - 'incorrect behaviour'.

1. Again select a file in the middle of the column.

2. Hold down shift and click on the file at the top of the column as before.

3. Hold down shift and as before click on the file at the bottom of the column.

Oops!

The above bug was introduced into OS X with Leopard 10.5.0, effectively crippling use of outline views and table views.

Despite 10.5 Leopard now being nearly a year old and having had five (5) updates this core mistake hasn't been corrected.

About | Buy | Forum | Industry Watch | Learning Curve | Products | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.