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 3347266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:24:05+00:00 2026-05-18T01:24:05+00:00

I am trying to get a UIWebView to update dynamically, sort of like a

  • 0

I am trying to get a UIWebView to update dynamically, sort of like a karaoke box, as it iterates through a while loop. The word that the tts engine is speaking should be in orange (or in html, .style2).

What is happening, however, is that the UIWebView doesn’t update its display through each iteration of the htmlKaraoke string, but only the last one in the while loop. UIWebView appears to be reloading in a lazy way, and waiting until the while loop is finished before updating it’s display. I’ve included in my code all the different ways I’ve tried to circumvent this (setNeedsDisplay, setNeedsLayout, reseting the htmlKaraoke string, reloading the UIWebView) but I can’t seem to get it to do what I want.

The html code is updating like it should (with the spoken word in orange), but the webview isn’t reflecting this.

How can I get the webView to update after every update of the htmlKaraoke string?

i = 0;
NSString *htmlHead              = @"<html><head><style type='text/css'><!-- .style1 { font-size: 24px; font-weight: bold; font-family: Helvetica; } .style2 {color: #FF9900} --> </style></head><body><span class='style1'>";
NSString *htmlFoot              = @"</span></body></html>";
NSString *htmlEmpHead           = @"<span class='style2'>";
NSString *htmlEmpFoot           = @"</span>";
NSMutableString *htmlKaraoke = [[NSMutableString alloc] init];

while(i <= wordWeAreUpToInt){
    //wait until the tts is finished talking.
    if(![[fliteEngine audioPlayer] isPlaying]){
        //NSLog(@"flite is finished!");

        //Add the word and highlight in the karaoke

            /*  Clear the html string
                Make a for loop, where n = 0, n<i, n++
                    append black word
                when for loop ends, and n == i, add an emph word (n==i when i is the currently spoken word). 
             */
        [karaokeWebView loadHTMLString:@" " baseURL:nil];
        [karaokeWebView reload]; //doesn't do anything. These two lines are a waste of breath. 

        [htmlKaraoke setString:htmlHead];
        for (int n = 0; n<i; n++) {
            [htmlKaraoke appendString:[wordsArray objectAtIndex:n]];
            [htmlKaraoke appendString:@" "];
        }
        [htmlKaraoke appendString:htmlEmpHead];
        [htmlKaraoke appendString:[wordsArray objectAtIndex:i]];
        [htmlKaraoke appendString:@" "];
        [htmlKaraoke appendString:htmlEmpFoot];
        NSLog(@"Emphasis: %@", [wordsArray objectAtIndex:i]);           
        [htmlKaraoke appendString:htmlFoot];


        NSLog(@"htmlKaraoke: %@", htmlKaraoke);

        [karaokeWebView loadHTMLString:htmlKaraoke baseURL:nil];
        [karaokeWebView setNeedsDisplay];
        [karaokeWebView setNeedsLayout]; //getting desperate....!

        //speak the word
        [self readSentence:[wordsArray objectAtIndex:i]];
        i++;
    }
}

[htmlKaraoke release];
wordWeAreUpToInt++;
}
  • 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-18T01:24:06+00:00Added an answer on May 18, 2026 at 1:24 am

    I think your problem is that UIWebView only renders the view after control returns back to the main NSRunLoop / Event Loop. So, if you’re making all of your updates within the while loop above, then only the last string is getting loaded as it never got the chance to load the other ones (& so will just use the last load request).

    You will need to return out of any code you’ve written (not just this method, but also whatever triggered this being called, etc.) and return control back to the OS, before the UIWebView will update with your changes.

    Assuming that whatever object this code is in is still around after control returns, you could test this out by adding this to your class:

    - (void)loadHTMLString:(NSString *)string {
        [karaokeWebView loadHTMLString:string baseURL:nil];
    }
    

    And then change your -[loadHTMLString:baseURL:] calls into:

    [self performSelector:@selector(loadHTMLString:) withObject:htmlKaraoke afterDelay:_delay_increasing_by_a_second_for_each_string];
    

    There’s more on the main “Event Loop” in the “Application Life Cycle” section of the “iOS Application Programming Guide”.

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

Sidebar

Related Questions

Trying to get my css / C# functions to look like this: body {
Trying to get an ASP application deployed; it worked for a while but then
I'm trying to launch embedded Youtube videos from a UIWebView, but get this error
I am trying to get the HTML source of a UIWebView without re-downloading it
I'm trying to use a UIWebView to display content, and jQuery to manipulate that
I am trying to access a secure website through UIWebView. When I access it
I'm trying to get a UIWebView working with the following code: NSString *urlAddress =
I am trying to load a html page through UIWebview.I need to disable all
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get

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.