The problem is that you need to spawn a thread to do your work, and then
have the spawned thread make threaded calls to the main thread using
performSelectorOnMainThread to update the screen. I wrote up a revised blog
entry at
http://www.pacificspirit.com/blog/2009/02/25/iphone_threading_and_screen_refreshes_success
The following fragment illustrates what works:
- (void)doSomethingSlow:(id)sender
{
[self outputString:@"doSomethingSlower:\n"];
[NSThread detachNewThreadSelector:@selector(slowTransfer) toTarget:self
withObject:nil];
}
- (void) doneTransfer
{
NSLog(@"DoneTransfer");
}
- (void)slowTransfer
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do processing here.
[self performSelectorOnMainThread:@selector(setProgressValue:)
withObject:[NSNumber numberWithFloat:i/10.0] waitUntilDone:NO];
// When done...
[self performSelectorOnMainThread:@selector(setProgressValue:)
withObject:[NSNumber numberWithFloat:1.0] waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(doneTransfer) withObject:nil
waitUntilDone:YES];
[pool release];
}
- (void)setProgressValue:(NSNumber *)progressValue
{
self.progressView.progress = [ progressValue floatValue];
}
On Fri, Feb 20, 2009 at 12:38 PM, SPIE <[email protected]> wrote:
>
> I'm having a problem with what I thought would be a very simple task.
> I'm developing a browser based app in Dashcode. When the user clicks a
> row in a list I want to replace the small arrow image with an activity
> indicator to show the request is in process. The logical approach, I
> thought, was to add code in the row's handler function that set the
> arrow display style to none and the indicator display style to an
> empty string. Unfortunately that doesn't seem to work. Well, it does
> but too late to do any good. After the user clicks the row it sits in
> the highlighted state while the request completes and then right
> before it transitions to the next screen the arrow disappears and the
> indictor shows. I've also tried circumventing the handler function by
> adding my own call back action. Same results.
>
> It strikes me odd that such a fundamental piece of the user experience
> isn't better supported by Dashcode.
>
> So I guess I have two questions:
> 1. Is there a better method for dealing with activity indicators?
> 2. Should I be using a different method to show and hide elements in
> the UI? I've tried the display and visibility properties and also
> tried creating a new element in code and tacking it on to the row
> programmatically (similar to the the way row highlighting works).
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---