5

I'm trying to show a fully loaded webview. I don't want the user to see the webview in the loading process. I'm handling a few webviews at a time and using webViewDidFinishLoad makes it a lot more complex for me so I'm trying to do something like this:

while(_lastWebView.isLoading)
{
_lastWebView.hidden=YES;
}

_lastWebView.hidden=NO;

But I get this msg: void SendDelegateMessage(NSInvocation *): delegate () failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

I don't understand why is entering a loop because isLoading returns 0 when the loading is finished.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Segev
  • 19,035
  • 12
  • 80
  • 152
  • 1
    You've coded an infinite loop. (Though to be completely accurate, it's not "infinite", just very, very, very, very long. Sooner or later something will kill it.) – Hot Licks Mar 07 '13 at 19:59
  • 4
    (You should never wait in the UI task, and never, never, never use a "spin loop" to wait for something.) – Hot Licks Mar 07 '13 at 20:01
  • How should I wait for something then? – Segev Mar 07 '13 at 20:02
  • 1
    You shouldn't. Instead of waiting to do something, do it when what you're waiting for happens. (In this case, that would probably be in the `webViewDidFinishLoad:` method you mentioned.) – Peter Hosey Mar 08 '13 at 05:31

1 Answers1

8

Don't block your UI with that loop. It will stop the user from doing anything else on the main thread.

Instead, count the number of requests your webView makes, and make it visible when it's done loading.

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287