Re: Handling List of Hardware Devices in NSTableView w/ Asynchronous Updates
Re: Handling List of Hardware Devices in NSTableView w/ Asynchronous Updates
- Subject: Re: Handling List of Hardware Devices in NSTableView w/ Asynchronous Updates
- From: Michael Ash <email@hidden>
- Date: Wed, 1 Apr 2009 11:02:09 -0400
On Wed, Apr 1, 2009 at 10:51 AM, Grant Erickson <email@hidden> wrote:
> I've a list of hardware devices in an NSTableView. The contents of the table
> view are updated accordingly using the device model (C++) getters in
> objectValueForTableColumn and using the device model setters in
> setObjectValue.
>
> However, the device model can also asynchronously create (sometimes
> rapidly-order of tens to hundreds of milliseconds) updates for one of the
> model values independently of the getter. To handle this, I currently have
> the controller implement a delegate method for these asynchronous updates
> and then do:
>
> [mDeviceTable reloadData];
>
> Unfortunately, this then causes the table to hit all the device getters for
> all the devices and update all the columns even though only a single column
> (and possibly row) has changed thereby creating needless bus traffic and
> activity.
>
> My first inclination is to create an array of dictionaries that act as a
> cache for the device attributes, have the asynchronous delegate update the
> appropriate key/value and then have reloadData update from there.
>
> Is this the best or recommended approach? I'm only vaguely familiar with
> Cocoa's KVC/KVO, but based on my understanding it also seems like a KVC/KVO
> wrapper for the C++ device model might also work.
You can cause the table view to update only a single row by simply
invalidating the rectangle covered by that one row and causing it to
redraw. Since the table doesn't cache any values, it will re-fetch
them from your data source. The documentation for the -rectOfRow:
method has a small example.
Depending on what you're doing, you might also want to cache the
values in an array, so that simple GUI updates (like scrolling the
table or resizing the window) don't have to hit your devices again.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden