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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:53:45+00:00 2026-06-12T21:53:45+00:00

I have inherited some bloody awful code that I am trying to debug. I’m

  • 0

I have inherited some bloody awful code that I am trying to debug.

I’m parsing an RSS feed, using NSXMLParser. In parser:didEndElement:etc:, as each new item appears, I fire another method that invoke’s a UITableView’s reloadData method. However, the reloadData methods are not called when they are invoked, but later … after parserDidEndDocument: … then they all fire at once.

It seems like the reloadData requests are queuing up somewhere, blocking on the parsing thread.

How can I force reloadData to fire when I tell it, not when it wants to. My problem is that since it only reloads after all the news items have loaded — and there are a lot of them — the UI experience is suboptimal.

  • 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-06-12T21:53:46+00:00Added an answer on June 12, 2026 at 9:53 pm

    Your conjecture is correct. Updates to the user interface are only done when program control returns to the main run loop. NSXMLParser however works completely synchronously: The parse method parses the entire XML data (calling the delegate functions etc) and returns only when parsing is done. Calling reloadData in parser:didEndElement:... has therefore no immediately visible effect.

    If parsing your XML data really takes so much time that you cannot just call reloadData when the parse method has returned, you have to move the parsing operation to a separate thread:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [myParser parse];
    });
    

    dispatch_async returns immediately and the parsing in done on a background thread.
    The delegate methods are therefore also called on the background thread. Since updates to the UI must only be done on the main thread, you could proceed as follows in
    parser:didEndElement:...:

    YourType newObject = ... // create new object from XML data
    dispatch_async(dispatch_get_main_queue(), ^{
        // assuming that self.dataArray is your data source array for the table view 
        int newRow = [self.dataArray count]; // row number for new object
        [self.dataArray addObject:newObject]; // add to your data source
        // insert row in table view:
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRow inSection:0];
        [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];
    });
    

    Using insertRowsAtIndexPaths instead of reloadData should give a “smoother” UI update with animation.

    I do hope that there are not too many syntax errors in my sample code and that it helps. Otherwise feel free to ask.

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

Sidebar

Related Questions

I have inherited some verbose, repetitious code that I am trying to refactor. The
I have inherited some code below that works fine, the only problem is, I
I have inherited some really old VC6.0 code that I am upgrading to VS2008
I have inherited some code which involves a scheduled task that writes data (obtained
I have inherited some code that queries a DB over a WCF service and
I have inherited some code that isn't quite working ... I have jsp which
I have inherited some code that is not working as I think it should:
I have some code that I have inherited that generates a matrix of significance
I have some inherited code that I am modifying. However, I am seeing something
I have some inherited code for FlexLM that is converting an integer to a

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.