Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: updating UI during long loop using cocoa objective-c




On 2007 Mar, 31, at 20:45, I. Savant wrote:


Well, without a separate thread, you could tell your table view or window to -display on each iteration. That'll force the display to update, but since you're blocking the main thread with your for loop, you'll still get the beach ball (I believe).

What I.S. believes is correct. This won't work.

For a multi-threaded approach, you'll want to search this list's archives for the term "appkit thread safe" as there are a number of issues to consider carefully *before* you start changing your design.

Allow me to return some good advice someone gave me a few weeks ago: Before you delve into multithreading, consider running your window as a "modal session". Poorly documented, no sample code, but simple if you can get it to work. Start by reading the documentation for:
-[NSApplication beginModalSessionForWindow:]
It's really weird because the NSModalSession is a struct, but just go along with it. Another hint: Use the strangely-named method:
-runModalSession:
when you want to update your view.


If the only UI you need to be active is one window, the modal session will theoretically get you there with much less code and bugs than multithreading. (Of course, it is multithreading under the hood, but Apple has done all the hard parts for you.) I've used a modal session with a simple window that has a progress bar and a Cancel button. I guess it should work with a table, but that might be pushing the envelope. Good luck and let us know if it works. _______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >updating UI during long loop using cocoa objective-c (From: <email@hidden>)
 >Re: updating UI during long loop using cocoa objective-c (From: "I. Savant" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.