On Dec 6, 2010, at 17:16, [email protected] wrote:

> On Dec 6, 2010, at 5:37 PM, Gustavo Pizano wrote:
> 
>> Hello.
>> 
>> My application is saving some data, and it takes a while to do it, it can be 
>> 1 second to 10 sec around.. Im doing some image processing,  The thing is..
>> 
>> I send the saving operation in another thread using the NSThread + 
>> detachNewThreadSelector:toTarget:withObject: method,  and in the main thread 
>> I update a UIActivityIndicator, and stop it when I receive the 
>> NSThreadWillExitNotification.  The problem is that when it takes long to 
>> save, it may seem the app is somehow stuck, even the spinning indicator is 
>> running. I wanted to change the ActivityIndicator to a progressview, but 
>> then I can't make it work because the saving process not on the main thread, 
>> i think.. correct me if Im wrong, Im not so much familiar with multithreaded 
>> apps.
>> 
>> As for the saving process, what I do is the following.
>> 
>> I have a Parent view which contains subviews, these subviews are drawing 
>> images. The user can modify this images, (scale and rotate), so when I save 
>> i encode these views so it will save the view's transform,  and then  I 
>> archive the data I encoded for all these subviews.
> 
> 
> <your code deleted>
> 
> You are correct that you cannot call GUI methods from other threads, but 
> NSObject (which all your UI objects inherit from) has the method.
> 
> - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg
> 
> So from your other thread, you can update the progress indicator by using it 
> to call a method that updates the progress. 
> 
> 
> This is even easier if you are targeting iOS 4.0 and higher using Blocks and 
> GrandCentral Dispatch.
> 
> Code typed in email (i.e., not tested):
> 
>   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
> 0), ^{
>        // code you want implemented on another thread goes here:
> 
>        dispatch_async(dispatch_get_main_queue(), ^{
>           // code executed on main thread goes here (i.e., updating the 
> progress indicator in your case
> 
>        });
>    });
> 
> HTH,
> Dave

Maybe I'm missing something but aren't the UI actions supposed to happen in the 
main thread, in this case, he should really call 
"performSelectorOnMainThread:withObject:waitUntilDone:"?

-Laurent.
-- 
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin                                 
http://www.nemesys-soft.com/
Logiciels Nemesys Software                                              
[email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to