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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:51:39+00:00 2026-06-17T08:51:39+00:00

I am developing an iOS app with a UITableView which at some stage adds

  • 0

I am developing an iOS app with a UITableView which at some stage adds or removes a bunch of its rows. Since there are a large number of rows, this operation can take long. However, I cannot easily determine if it will take a long time or not.

I would like to display a UIActivityIndicator (spinner) only if this operation is taking a long time. The way that I’ve always done this, is to start the lengthy operation, and after some delay (say 0.5 seconds) we test if the operation is still running, and if it is, we start displaying the UIActivityIndicator.

If you can run the lengthy operation in a background thread, this is no problem. However, this particular case is tricky because the lengthy operation (deleteRowsAtIndexPaths:withRowAnimation:) must run in the main thread (if I run this method in a background thread, the app crashes occasionally when the background thread tries to update the UI).

The latest thing that I’ve tried was in the lines of this:

- (void) manipulateTableView
{
    stillBusy = YES;
    [self performSelectorInBackground:@selector(waitBeforeShowingBusyIndicatorForView:) withObject:view];
    .
    .
    .
    [self performSelectorOnMainThread:@selector(deleteRowsAtIndexPathsWithRowAnimation:) withObject:args waitUntilDone:YES];
    stillBusy = NO;
}

- (void) waitBeforeShowingBusyIndicatorForView:(UIView*) view
{
    usleep((int) (BUSY_INDICATOR_DELAY * 1000000));
    if (stillBusy)
        [self performSelectorOnMainThread:@selector(showBusyIndicatorForView:) withObject:view waitUntilDone:NO];
}

Because showBusyIndicatorForView: manipulates the UI, it must be called on the main thread, otherwise the app might crash.

When deleteRowsAtIndexPaths:withRowAnimation: takes very long, the delay in waitBeforeShowingBusyIndicatorForView: expires and the performSelectorOnMainThread:… method is called and returns immediately. But then the showBusyIndicatorForView: method is called only after the call to deleteRowsAtIndexPaths:withRowAnimation: completes, which defeats the purpose.

I think I understand why this happens. The deleteRowsAtIndexPaths:withRowAnimation: method runs in an iteration of the main loop, and while it’s running, the call to showBusyIndicatorForView: is queued as a message of the main loop. Only after main loop completes executing deleteRowsAtIndexPaths:withRowsAnimation: it polls the queue for the next message and then starts executing showBusyIndicatorForView:.

Is there any way of getting this thing to work properly. Is it perhaps possible to interrupt the main loop and make it execute showBusyIndicatorForView: immediately?

  • 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-17T08:51:40+00:00Added an answer on June 17, 2026 at 8:51 am

    Rob, thanks for the advice! It helped me find a solution!

    First of all, and for the record, I was calling deleteRowsAtIndexPaths only once for all the rows (several thousands of them :O!).

    The key observation that I made was that only a small number of the rows are visible on the screen when the animation starts. Specifically the top rows of the section, because the removal of the rows is triggered by tapping the header of that section. Because of this, the rows need not all be part of the animation. I can remove all the non-visible rows first (without an animation), and then remove just the visible rows with an animation.

    I then had two calls to deleteRowsAtIndexPaths – the first one removed all the non-visible rows, and the second one removed the visible (top) rows. Now the first call to deleteRowsAtIndexPaths took a very long time, because it had to remove thousands of rows, and again the activity indicator view could not get a chance to begin animating. I then changed the first phase of the row-removal to a loop that removed the rows 200 at a time like this:

    for ( /* next range of invisible rows */ )
    {
        // Compute index paths of the bottom 200 rows.
        [self performSelectorOnMainThread:@selector(deleteRowsAtIndexPathsWithRowAnimation:) withObject:args waitUntilDone:YES];
    }
    

    The method that starts the activity indicator animation would then be queued between two subsequent calls to deleteRowsAtIndexPaths…:.

    Interesting to note: now that I’m removing 200 rows at a time, it takes a considerable while, but it’s still significantly faster than when I remove them all at once! 😐

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

Sidebar

Related Questions

I'm developing a simple iOS app where there is a table view with some
I'm developing an iOS app. Its working properly on simulator. I'm using phonegap and
I'm developing an iOS app which asks the user to either login or signup
I am developing a iOS app in which I am using Core Data. I
I'm developing iOS app which uses HLS. In our video platform we use Nginx
I'm developing an iOS app in which I want a scroll bar like element
I am developing an iOS app in which I am streaming .mp3 files using
I am developing an iOS app which saves picture in an Amazon S3 server.
I am developing an iOS app in which it is required to change the
I'm developing an iOS app. There are different 'areas' to the app, and users

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.