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

  • Home
  • SEARCH
  • 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 3946390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:07:40+00:00 2026-05-20T01:07:40+00:00

I currently have a very simple view which displays info from a JSON feed.

  • 0

I currently have a very simple view which displays info from a JSON feed. The problem I’m facing is the few second pause I encounter once I press this tab. How can I make this view load instantly and then have the label.text areas load after? Preferable with an activity indicator?

Should I use threads?

Thanks in advance!

Code:

- (NSString *)stringWithUrl:(NSURL *)url {
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:30];
    NSData *urlData;
    NSURLResponse *response;
    NSError *error;

    urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
    }


- (id)objectWithUrl:(NSURL *)url {
    SBJsonParser *jsonParser = [SBJsonParser new];
    NSString *jsonString = [self stringWithUrl:url];
    return [jsonParser objectWithString:jsonString error:NULL];
    }


- (NSDictionary *)downloadStats {
    id response = [self objectWithUrl:[NSURL URLWithString:@"http://www.example.com/JSON"]];
    NSDictionary *feed = (NSDictionary *)response;
    return feed;
    [feed release];
    }

- (void)viewDidLoad {
    [super viewDidLoad];

    [GlobalStatsScrollView setScrollEnabled:YES];
    [GlobalStatsScrollView setContentSize:CGSizeMake(320, 360)];
}

- (void)viewWillAppear:(BOOL)animated {
    NSLog(@"View appears");

    // Download JSON Feed
    NSDictionary *feed = [self downloadStats];      
    totalproduced.text = [feed valueForKey:@"Produced"];
    totalno.text = [feed valueForKey:@"Total"];
    mostcommon.text = [feed valueForKey:@"Most Common"];
    }
  • 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-20T01:07:40+00:00Added an answer on May 20, 2026 at 1:07 am
    - (void)viewWillAppear:(BOOL)animated {
        NSLog(@"View appears");
    
        UIActivityIndicatorView* spiner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
        spiner.tag = 123;
        [self.view addSubview: spiner];
        [spiner startAnimating];
        [spiner release];
    
        NSThread* thread = [[NSThread alloc] initWithTarget: self 
                                                   selector: @selector(loadFeed) object: nil];
        [thread start];
    
    }
    
    -(void) loadFeed {
        // Download JSON Feed
        NSDictionary *feed = [self downloadStats];      
        totalproduced.text = [feed valueForKey:@"Produced"];
        totalno.text = [feed valueForKey:@"Total"];
        mostcommon.text = [feed valueForKey:@"Most Common"];
    
        [[self.view viewWithTag: 123] removeFromSuperview];
    }
    

    don’t forget to release your thread after.
    You should also check docs for NSOperationQueue

    Another option would be using asynchronous requests.

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

Sidebar

Related Questions

I have written a VERY simple MVC application which just displays a single string
I have a very large app, 1.5 million lines of C++, which is currently
Currently in our enterprise we have a situation that i think it's not very
I'm working on a very graphic-heavy application which uses content from a bunch of
I have a view which consists of a tableview and a navigation bar. For
I have put together a script which is very much like the flickr photostream
I'm currently writing a very simple game engine for an assignment and to make
I created a simple .Net web service which runs a very simple query (which
I have a fresh install of CakePHP 1.3.4 Stable. I created a very simple
I have a simple test page in my Silverlight 4 application in which I'm

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.