Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:32:13+00:00 2026-05-24T07:32:13+00:00

I want to load some HTML in a UIWebView: – (IBAction)buttonClicked:(id)sender { [webView loadHTMLString:@Hello

  • 0

I want to load some HTML in a UIWebView:

- (IBAction)buttonClicked:(id)sender {
    [webView loadHTMLString:@"Hello World" baseURL:nil];
    // a lot of other time-consuming code that has to perform in main thread
}

The problem is, that the UIWebView starts loading AFTER the “other time-consuming” code is finish. I want, that the UIWebView starts loading directly. Does the UIWebView wait for the main thread and starts loading after all events in the main thread are processed?

Can I force the main thread to process everything?

- (IBAction)buttonClicked:(id)sender {
    [webView loadHTMLString:@"Hello World" baseURL:nil];
    // !!! main thread, please PERFORM everything until here BEFORE going on !!!
    // a lot of other time-consuming code that has to perform in main thread
}

PS: The following workaround works, but I think it isn’t the best solution 😉

- (IBAction)buttonClicked:(id)sender {
    [webView loadHTMLString:@"Hello World" baseURL:nil];
    [NSThread detachNewThreadSelector:@selector(startNewThread) toTarget:self withObject:nil];
}

- (void)startNewThread {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
    [NSThread sleepForTimeInterval:1];
    [self performSelectorOnMainThread:@selector(goBackToMainthread) withObject:nil waitUntilDone:NO];  
    [pool release];     
}

- (void)goBackToMainthread {
    // a lot of other time-consuming code that has to perform in main thread    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:32:14+00:00Added an answer on May 24, 2026 at 7:32 am

    Use the same thread to process everything (especially time consuming stuffs) is not a good idea.

    When you are doing something time consuming on the thread responded for UI, the whole UI will be frozen, and it will not be able to give any response to the user, e.g. buttons will not change color when you touch it.
    So you should separate your time consuming stuffs and UI stuffs on different threads.

    Next, the UIKit is not thread-safe (except drawing to a graphics context), which means you should not do anything related to the UI outside of the main thread.

    So the conclusion will be: Process your time consuming stuffs on another thread, not the main thread.
    This parts is very easy with iOS4’s GCD, the following code should do:

    #include <dispatch/dispatch.h>
    
    [webView loadHTMLString:@"Hello World" baseURL:nil];
    dispatch_queue_t myQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(myQueue, ^{
        //Do something time consuming here
    });
    

    Note that the default queue in the above example will process tasks concurrently, if you want to manage the queue(s) yourself, you may create it like this:

    dispatch_queue_t myQueue = dispatch_queue_create("com.mycompany.myqueue", 0);
    

    More details can be found on Session 211 of WWDC 2010 Session Videos: Simplifying iPhone App Development with Grand Central Dispatch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use WebBrowser control to load some localfile html page. I am
I'm trying to load in my WebView some HTML code that contains JavaScript. Now
I want to load some images into my application from the file system. There's
I want to load some data from mysql into my cocoa application view before
I want to load some helper in a model. How to do this? Tried
i want to load some photos into my sd card image in the emulator.
I want to load some .css files to my Django project but I don't
I have a UINavigationController consisting of a tableview I want to load some data
For my current project I want to be able to load some classes from
Suppose i have some tabs (e.g. jquery tab) and I want to dynamically load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.