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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:59:18+00:00 2026-05-23T12:59:18+00:00

Hi in my app I load a NSString from Internet using NSURL, and then

  • 0

Hi in my app I load a NSString from Internet using NSURL, and then a label shows the text. If i press the button to load the String, it becomes highlighted and stays highlighted for a couple of seconds. During that time i want a UIActivityIndicatorView to show up, to inform the user that the app is actually doing something. Ive tried just adding [activity startAnimating]; to the IBAction but it only starts animating when the button is back to the default state, not when its highlighted. ive also tried
if ([button state] == UIControlStateHighlited) {
[activity startAnimating];
}

but it doesn’t work.


awesome, now it works! Thanks a lot! You forgot to put [spinner start animating] into the code :D. There was a bug that if you pressed the button many times in a row the app would crash, so it got rid of it:

- (IBAction)load:(id)sender { 
if ([act isAnimating]) {
}
else {
ASINetworkQueue *queue = [ASINetworkQueue queue];
ASIHTTPRequest *usdRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADUSD=X&f=l1"]];
ASIHTTPRequest *eurRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=l1"]];
ASIHTTPRequest *dateRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=d1"]];
ASIHTTPRequest *timeRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=t1"]];

[queue addOperation:usdRequest];
[queue addOperation:eurRequest];
[queue addOperation:dateRequest];
[queue addOperation:timeRequest];

[queue setQueueDidFinishSelector:@selector(parseLoadedData:)];
[queue setRequestDidFinishSelector:@selector(requestLoaded:)];
[queue setDelegate:self];
[queue go];
[act startAnimating];
}
}

  - (void)requestLoaded:(ASIHTTPRequest *)request {
 if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADUSD=X&f=l1"]]) {
    usdString = [[request responseString] retain];
} else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=l1"]]) {
    eurString = [[request responseString] retain];
} else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=d1"]]) {
    dateString = [[request responseString] retain];
} else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=t1"]]) {
    timeString = [[request responseString] retain];

}
}

- (void)parseLoadedData:(ASIHTTPRequest *)request {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *Date = [dateString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSString *Time = [timeString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSString *total = [NSString stringWithFormat:@"%@ %@",Date,Time];

if ([eurString length] == 0) {
    test.text = [defaults objectForKey:@"date"];
    eur.text = [defaults objectForKey:@"eur"];
    usd.text = [defaults objectForKey:@"usd"];

} else {
    test.text = total;
    eur.text = eurString;
    usd.text = usdString;
    [defaults setObject:test.text forKey:@"date"];
    [defaults setObject:usd.text forKey:@"usd"];
    [defaults setObject:eur.text forKey:@"eur"];
}

[defaults synchronize];
[eurString release];
[usdString release];
[dateString release];
[timeString release];
[act stopAnimating];

}
  • 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-23T12:59:18+00:00Added an answer on May 23, 2026 at 12:59 pm

    I think that you should rewrite your code. Maybe I’ll do it for you. 🙂

    First of all, download [ASIHTTPRequest library][1]. It’s great library for working with network files. I think that you should use queue for this.

    Then put this code in your view controller:

    - (IBAction)buttonClicked:(id)sender {
    
        ASINetworkQueue *queue = [ASINetworkQueue queue];
    
        ASIHTTPRequest *usdRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADUSD=X&f=l1"]];
        ASIHTTPRequest *eurRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=l1"]];
        ASIHTTPRequest *dateRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=d1"]];
        ASIHTTPRequest *timeRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=t1"]];
    
        [queue addOperation:usdRequest];
        [queue addOperation:eurRequest];
        [queue addOperation:dateRequest];
        [queue addOperation:timeRequest];
    
        [queue setQueueDidFinishSelector:@selector(parseLoadedData:)];
        [queue setRequestDidFinishSelector:@selector(requestLoaded:)];
        [queue setDelegate:self];
    
        [queue go];
    
    }
    
    - (void)requestLoaded:(ASIHTTPRequest *)request {
        if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADUSD=X&f=l1"]]) {
            usdString = [[request responseString] retain];
        } else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=l1"]]) {
            eurString = [[request responseString] retain];
        } else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=d1"]]) {
            dateString = [[request responseString] retain];
        } else if([[request url] isEqual:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=CADEUR=X&f=t1"]]) {
            timeString = [[request responseString] retain];
        }
    }
    
    - (void)parseLoadedData:(ASIHTTPRequest *)request {
    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
        NSString *Date = [dateString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
        NSString *Time = [timeString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    
        NSString *total = [NSString stringWithFormat:@"%@ %@",Date,Time];
    
        if ([eurString length] == 0) {
            test.text = [defaults objectForKey:@"date"];
            eur.text = [defaults objectForKey:@"eur"];
            usd.text = [defaults objectForKey:@"usd"];
    
        } else {
            test.text = total;
            eur.text = eurString;
            usd.text = usdString;
            [defaults setObject:test.text forKey:@"date"];
            [defaults setObject:usd.text forKey:@"usd"];
            [defaults setObject:eur.text forKey:@"eur"];
        }
    
        [defaults synchronize];
        [eurString release];
        [usdString release];
        [dateString release];
        [timeString release];
    
        [yourSpinner stopAnimating];
    
    }
    

    In your header file declare theese objects:

    NSString *usdString;
    NSString *eurString;
    NSString *dateString;
    NSString *timeString;
    

    I think that it will work. 😉


    EDIT: I updated the code so that is must work. I checked it myself. My method of loading your data is faster, safer and more efficient.

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

Sidebar

Related Questions

I load a UIWebView from a string in a navigation based app. I'm using
My app has to load an image from a http server and displaying it
When I load my iPhone app it always loads a black screen first then
I have an app that checks for a file upon load from the appDelegate's
I have a UITableView in my app in which I load several images from
I'm using the demo example in https://github.com/nicklockwood/AsyncImageView to load images asynchronously, however my app
I am trying to load JSON from a sever and then display it in
I want to load images from UIImagePickerController, then save the selected photo to my
in my app I have a section where I load from a saved plist
I have a tableview to load news from internet. I and trying to nil

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.