Error when loading UIWebView in a separate thread

Discussion in 'iOS Programming' started by walty, Oct 6, 2008.

  1. walty macrumors member

    Jul 15, 2008
    Hi All,

    Currently trying to load a UIWebView in a separate view, and from time to time (but not always), the program crashes with the following error:

    But the problem does not appear when I run the program on device. And it seems there is no corresponding record in Google (one actually, but no solution mentioned).

    For safety caution, I already set the max concurrent operation to be 1, and the main UI thread would not load any other webview.

    Any hint please?

  2. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    The UI isn't reentrant, you can only call, modify or load the UI from your main thread. You can preload data into a non-UI object in a separate thread, if needed.

  3. walty thread starter macrumors member

    Jul 15, 2008

    Thanks for reply firewood, but I am still a bit confused, if I prefetch the data using a separate thread, how am I going to collect the data from the main UI thread, should I use a timer-like thing or an asynchronous call? In either case, I thought a separate thread should still be created (either explicitly or implicitly) to update the UI.

    If the main thread just waits the separate thread to finish prefetching thread, the UI would still be hanged anyway, I guess?

    Actually, I found more and more mysterious issues when trying to update UI in separate thread, and still this issue seems to occur only on simulator, and never reproduced on the device... Just not sure if this is an issue of simulator, or a hidden huge bug in my program.. :confused:
  4. walty thread starter macrumors member

    Jul 15, 2008
    Ok, I got it, the key is:

    - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
    Now, most of the mysterious issues gone, thx a lot :)

Share This Page