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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:44:06+00:00 2026-05-26T04:44:06+00:00

I have been working on my first app for some time now, but it

  • 0

I have been working on my first app for some time now, but it seems that I am missing something here. The code below was originally only in my app delegate; I just added a refresh button in the first view controller in order to refresh the data the app uses, so my first idea was to call the app delegate code again inside the view controller, but the NSURLConnection delegate methods did not fire. Now I have added the code to the view controller (and also kept it in the app delegate) and the delegate methods fire when the refresh button is pressed, but responseData is null, refreshString is empty and JSONValue throws an “Unexpected end of input” error (because nothing is being inputted) in the log (the app still runs and clears the UITableView, this is proper behavior since the array is now empty). The JSON data’s character set is UTF-8

There may be a better place for this code where it can be kept in one place and run as needed, and if there are any suggestions regarding that I would appreciate them as well, but my primary concern is figuring out why this code works correctly the first time, but does not work the second.

- (void) refreshData{
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://beersandears.net/beer-list-json.php?native=yes"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
    NSLog(@"loadData complete");
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
    NSLog(@"Response received");
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
    NSLog(@"Data received");
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [connection release];
    //label.text = [NSString stringWithFormat:@"Connection failed %@", [error description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];
    connection = nil;
    NSString *refreshString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

    [responseData release];

    NSDictionary *results = [refreshString JSONValue];

    BeerListAppDataObject* theDataObject = [self beerListAppDataObject]; 

    [theDataObject.beerList removeAllObjects];
    [theDataObject.mapList removeAllObjects];
    [theDataObject.blogList removeAllObjects];

    theDataObject.beerList = [results objectForKey:@"beer"];
    theDataObject.mapList = [results objectForKey:@"map"];
    theDataObject.blogList = [results objectForKey:@"blog"];

    NSLog(@"Data Loaded");

    [self.tableView reloadData];
}
  • 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-26T04:44:07+00:00Added an answer on May 26, 2026 at 4:44 am

    You’re releasing the NSData responseData member variable in finishLoading:

    [responseData release];
    

    But, I don’t see anything else getting another NSData object to append.

    In this sample code here:

    http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

    when they start the connection again (in your refreshMethod), they do:

    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (theConnection) {
        // Create the NSMutableData to hold the received data.
        // receivedData is an instance variable declared elsewhere.
        receivedData = [[NSMutableData data] retain];
    } else {
        // Inform the user that the connection failed.
    }
    

    The key line being this where they get an NSMutabaleData object and retain it.

    receivedData = [[NSMutableData data] retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my first iPhone app and have been able to get most
I have been working on an iPad app. My app contains some PDF and
I have been working with AJAX for a while now, but in limited and
I'm new to X-Code and have just started working on my first app. I'm
I have been working on building my first CSS site using divs and am
I have been working on this app for at least 3-4 months and just
I have been working on a project on and off, but I haven't touched
I have been working with Zend for a few months now and am at
This is my first time trying to accomplish core data and been having some
I have been working with this for a whole day but i cannot find

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.