0

In my iOS app (a kind of flashCard application) I'm using a UIWebView and once the webview content loading is finished I need to perform some UI operations (changes).
I'm checking for this in webViewDidFinishLoad.
When a user taps on a card it will flip and different content is gets loaded. I am using the code below in this flipAction as well as in swipeAction (when user moves from one card to another) to check:

if (![[myWebView stringByEvaluatingJavaScriptFromString:@"document.readyState"] isEqualToString:@"complete"])
{
    [self performSelector:@selector(myCustomMethod:) withObject:self afterDelay:3.0];
}

Sometimes, not always, my UI will freeze on the above if condition and after that the UI will not respond further. The app must be manually killed and relaunched.

Do I need to call stringByEvaluatingJavaScriptFromString: method other than thread? or what may be the cause for this?

2
  • Are you performing some UI updates in the if block? Does the code you posted run on the main thread? Commented Jan 27, 2014 at 14:49
  • Ya I'm performing UI Updates using main thread only. Commented Jan 27, 2014 at 14:56

1 Answer 1

1

You can try background thread

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
    dispatch_async(queue, ^{
        // async operation
        // Call your method here

                dispatch_sync(dispatch_get_main_queue(), ^{
                    // Update UI here

                });
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.