fill the void

Posted
6 December 2008 @ 5pm

Tagged
development

9 Comments

NSProgressIndicator in NSTableView or NSOutlineView

Spinning wheels (NSProgressIndicator objects in Cocoa) are a common UI element in, well, all software these days. People like to know if applications are busy doing something and, if so, how much longer they’ll be. Web browsers, for instance, have continuous spinning wheels to indicate that they’re still downloading the requested page and discrete progress bars to show how much of a file they’ve already downloaded.

In Cocoa, NSProgressIndicator is easily placed into an NSView using Interface Builder, but embedding the object in a list (NSTableView or NSOutlineView) takes a bit of coding. CocoaDev discusses it, but I thought I’d throw together a simple project demonstrating it, pictured above. It’s available on Google Code and as a zipped file (Xcode 3.1).


9 Comments

Posted by
nick
7 August 2009 @ 11am

I’ve been looking for an elegant way to implement progress indicators in an NSCell for an app I’m working on. This is definitely the cleanest way I’ve seen yet. Nice work.


Posted by
bdunagan
7 August 2009 @ 10pm

Glad you found it useful!


Posted by
Vijay Swami
13 August 2009 @ 11pm

Thanks a ton dear! You have saved hours of time for me.. now this is the real contribution to the world..nice work! Please keep helping people like me who switch to mac from windows..:)


Posted by
Simon Ward
13 September 2009 @ 4pm

Very clean and tidy code. If only all code examples could be as clear as this.
I like it very much!


Posted by
Simon Ward
13 September 2009 @ 9pm

Can it be done with bindings instead of a datasource?


Posted by
fill the void – Syncing Arrows in iTunes
25 September 2009 @ 10pm

[...] Cocoa object; those objects only display the spinning lines for isIndeterminate:YES (see my NSProgressIndicator example from last year). Instead, that nice UI feedback is created through home-brewed [...]


Posted by
bdunagan
11 October 2009 @ 11am

You can make bindings work in this case, but I still find I need to compose the progress into the model rather than into the cell. The problem with cell composition is there is only one progress object because of cell reuse, and multiple cells try to draw it at the same time. Please post a comment if you know how to do it. Thanks!


Posted by
Vladimir Solomenchuk
24 January 2010 @ 4pm

If you remove row, progress still remains in table. You have make own tableview with redefined reloadData method with code something like this

while ([[list subviews] count] > 0)
{
[[[list subviews] lastObject] removeFromSuperviewWithoutNeedingDisplay];
}


Posted by
cristik
26 January 2010 @ 7am

Thanks a lot for this solution. I managed to use bindings and added a UI category to the data model, so the MVC design is still in place.


Leave a Comment