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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:30:03+00:00 2026-05-23T06:30:03+00:00

I am trying to show an indicator view when loading data in viewDidLoad but

  • 0

I am trying to show an indicator view when loading data in viewDidLoad but the loading starts before i display the indicator, i guess that is because the view is not loaded until after. I have been reading a bit about this but just cannot get it to work.

What i would want is to display the activity indicator during the loading of the files into the database.

I have been doing testing so the code structure may look a bit weird.

Could someone nice please give me a hint, or a link, how to fix this so the activity indicator is shown when/if data is loaded from the .txt files into the DB?

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @" ";

loadActivityIndicator.hidden = TRUE;  // Hide UIActivityIndicationView at start



[self loadDataIfNeeded];
}

-(void)loadDataIfNeeded {
NSFileManager *fileManager = [NSFileManager defaultManager];

myFileArray = [[NSMutableArray alloc]init];

//======SET THE FILE INPUT NAME======//
qFileTxtName = @"110615";
[myFileArray addObject:qFileTxtName];
//===================================//

// CHECK IF THE FILE EXISTS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"checkQuestionFile.plist"];

if([fileManager fileExistsAtPath:path]) {
    NSArray *readKeyFileName = [[NSArray alloc] initWithContentsOfFile:path];

    if ([[readKeyFileName objectAtIndex:0] isEqualToString:qFileTxtName]) {
        //==== THERE IS NO UPDATED QUESTION .txt FILE ====//
    }
    else {
        //==== THERE IS AN UPDATED QUESTION .txt FILE ====//

        //  SET UP UIActivityIndicator view to show that work is ongoing
        loadActivityIndicator.hidden = FALSE;
        [loadActivityIndicator startAnimating];


        //==== SET UP PATH FOR ALL FILES====//

        NSString *aString = [[NSString alloc]init];

        aString = [@"questions_famquiz_hard_" stringByAppendingString:qFileTxtName];
        NSString *path1 = [[NSBundle mainBundle] pathForResource:aString ofType:@"txt"];

        aString = [@"questions_famquiz_medium_" stringByAppendingString:qFileTxtName];
        NSString *path2 = [[NSBundle mainBundle] pathForResource:aString ofType:@"txt"];

        aString = [@"questions_famquiz_easy_" stringByAppendingString:qFileTxtName];
        NSString *path3 = [[NSBundle mainBundle] pathForResource:aString ofType:@"txt"];


        AccessQuestionsDB *accessQuestionDataFunction = [AccessQuestionsDB new];
        idCounter = [accessQuestionDataFunction populateTheDatabase: path1 theID:0 firstTime: YES];
        idCounter = [accessQuestionDataFunction populateTheDatabase: path2 theID:idCounter firstTime: NO];
        idCounter = [accessQuestionDataFunction populateTheDatabase: path3 theID:idCounter firstTime: NO];


        //==UPDATE THE PLIST==//
        [myFileArray writeToFile:path atomically: TRUE];

        //  Stop UIActivityIndicator as activity is over
        loadActivityIndicator.hidden = TRUE;
        [loadActivityIndicator stopAnimating];


    }



} else {
    //== If file not found write a new file ==//
    [myFileArray addObject:qFileTxtName];
    [myFileArray writeToFile:path atomically: TRUE];
}
}

PROBLEM SOLVED

I replaced the call

[self loadDataIfNeeded];

with;

[NSThread detachNewThreadSelector:@selector(loadDataIfNeeded) toTarget:self withObject:nil];

to achieve multi threading according to the recommendation from Jonah 🙂

  • 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-23T06:30:04+00:00Added an answer on May 23, 2026 at 6:30 am

    You are loading your data synchronously in the main thread. That means that the main thread, the one responsible for drawing the UI, is busy loading your data and will not have a chance to update your view until after your loadDataIfNeeded method finishes (at which point you don’t want to show your activity indicator to be visible anymore anyway).

    Display your activity indicator on the main thread but then allow the main thread’s run loop to continue and instead perform expensive operations (like loading data or performing network requests) asynchronously on a secondary thread.

    Look at NSThread, NSObject‘s -performSelectorInBackground:withObject:, and NSOperationQueue for different options for performing tasks off of the main thread.

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

Sidebar

Related Questions

I'm trying to show/hide a movieclip (or graphic) symbol that is on a layer
I'm trying to show a custom hint in a TWinControl but I can't figure
I am really trying to show what htmlentities gives me, but it doesn't give
I'm trying to show a list of all users but am unsure how to
I'm trying to display a ProgressDialog to indicate that the user should wait while
I'm trying to add a way for my app to display data in an
Trying to show a label only when a certain item in a combo is
I'm trying to show someone a use for interfaces in a crazy situation they've
I am trying to show and hide an inline element (eg a span) using
I am trying to show the current date in my JSP page using JSTL.

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.