tags:

views:

180

answers:

1

Hi guys.

I call a javascript function and while waiting the return result i want to load an animation image (like: please waiting...).

//step1. call javascript
 NSString *resultMess = [webView stringByEvaluatingJavaScriptFromString:_scriptMethod];

//step2. want to load animation while waiting

//step3. after finish -> send alert

. How can I do stept2 and step3 ?

Thank you so much.

A: 

You can start a new thread. Add this before you you start your javascript function

[NSThread detachNewThreadSelector:@selector(loadAnimation) toTarget:self withObject:nil];

Then add whatever animation you want...

- (void)loadAnimation {

//Animation stuff here
}

You could try and run "step 3" immediately after your javascript stuff. So in all you would have

   - (void)someMethod {
    //start your animation 
    [NSThread detachNewThreadSelector:@selector(loadAnimation) toTarget:self withObject:nil];
    //run javascript
    NSString *resultMess = [webView stringByEvaluatingJavaScriptFromString:_scriptMethod];


    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show]

    }

If the javascript is causing your app to stall then the alert shouldn't pop up until after it finishes.

Brandon Schlenker
Thank you. It done well. I ask more:I want to alert return result from javascript method. But speed of javascript running is slowlier than iphone function speed so return will be empty ( Its mean that step3 do while step1 still doing ). Do you have solution to run step3 after step1 finish?
Just edit my original answer. I think that solves your problem.
Brandon Schlenker