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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:36:12+00:00 2026-06-10T01:36:12+00:00

I am having a hard time populating the tableview cells with json feed dates

  • 0

I am having a hard time populating the tableview cells with json feed dates field. I think it has do to with the way I am getting the dates

NSMutableArray *datesArray = [[NSMutableArray alloc] init];

    for (NSDictionary *tempDict in json){
        [datesArray addObject:[tempDict objectForKey:@"date"]];
    }

Please assist if you can. I have gone through everything I can think of (still learning).

.h file

#import <UIKit/UIKit.h>

@interface AvailabilityViewController : UIViewController <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
{

    NSDate *appointmentdate;
    UIActionSheet *dateSheet;
    UITextField *mydatetextfield;
    UILabel *pastDateLabel;
    NSArray *json;

}
//-(IBAction)getDataFromJson:(id)sender;

@property (strong, nonatomic) IBOutlet UITextField *mydatetextfield;
@property (nonatomic, retain) NSDate *appointmentdate;
@property (strong, nonatomic) IBOutlet UILabel *pastDateLabel;
@property (strong, nonatomic) IBOutlet UITableView *_tableView;
@property (nonatomic, retain) NSArray *json;
//-(void)setDate;
-(void)dismissDateSet;
-(void)cancelDateSet;



@end

.m file

- (void)fetchedData:(NSData *)responseData {
    //parse out the json data

    NSError* error;
    //NSLog(@"string is %@", responseData);

    self.json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    NSLog(@"string is %@", responseData);
    if ([json isKindOfClass:[NSArray class]]) {
        NSLog(@"its an array");
    } else if ([json isKindOfClass:[NSDictionary class]]) {
        NSLog(@"its a dictionary");
    }  else if ([json isKindOfClass:[NSString class]]) {
        NSLog(@"its a string");
    }  else if ([json isKindOfClass:[NSNumber class]]) {
        NSLog(@"its a number");
    }  else if ([json isKindOfClass:[NSNull class]]) {
        NSLog(@"its a null");
    } else if (json == nil){
        NSLog(@"nil");
    }
    //NSArray* latestLoans = [json objectForKey:@"date"]; //2
    NSMutableArray *datesArray = [[NSMutableArray alloc] init];

    for (NSDictionary *tempDict in json){
        [datesArray addObject:[tempDict objectForKey:@"date"]];
    }

    NSLog(@"this is your datesArray %@", datesArray);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.json.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
     cell.textLabel.text = [[self.json objectAtIndex:indexPath.row] objectForKey:@"date"];

    return cell;
    //[_tableView reloadData];
}  

Here is my NSLog of datesArray

2012-08-21 10:09:39.303 GBSB[1409:15b03] this is your datesArray (
    "2012-08-13 12:00:00",
    "2012-08-13 10:00:00",
    "2012-08-13 13:00:00"

Here is what the viewDidLoad looks like

- (void)viewDidLoad
{
    [super viewDidLoad];
    dispatch_async(kBgQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL: 
                        kLatestKivaLoansURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) 
                               withObject:data waitUntilDone:YES];

    });

}
- (void)fetchedData:(NSData *)responseData {
    //parse out the json data

    NSError* error;
    //NSLog(@"string is %@", responseData);

    self.json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    NSLog(@"string is %@", responseData);
    if ([json isKindOfClass:[NSArray class]]) {
        NSLog(@"its an array");
    } else if ([json isKindOfClass:[NSDictionary class]]) {
        NSLog(@"its a dictionary");
    }  else if ([json isKindOfClass:[NSString class]]) {
        NSLog(@"its a string");
    }  else if ([json isKindOfClass:[NSNumber class]]) {
        NSLog(@"its a number");
    }  else if ([json isKindOfClass:[NSNull class]]) {
        NSLog(@"its a null");
    } else if (json == nil){
        NSLog(@"nil");
    }
    //NSArray* latestLoans = [json objectForKey:@"date"]; //2
    NSMutableArray *datesArray = [[NSMutableArray alloc] init];

    for (NSDictionary *tempDict in json){
        [datesArray addObject:[tempDict objectForKey:@"date"]];
    }

    NSLog(@"this is your datesArray %@", datesArray);
    NSLog(@"this is the json %@", self.json);


    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
  • 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-10T01:36:13+00:00Added an answer on June 10, 2026 at 1:36 am

    You are creating a local variable called json in your fetchedData method and putting the parsed response in there. However, because this is a local variable it ceases to exist once your exit from the method.

    Instead, what you should do is to put the parsed response data into your viewController’s json @property which you declare in the .h file. To do this, make this change to your fetchedData: method:

    self.json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    

    Then in your cellForRowAtIndexPath: you can pull out the data like this:

    cell.textLabel.text = [[self.json objectAtIndex:indexPath.row] objectForKey:@"date"]
    

    Also your numberOfRowsInSection: should return:

    return self.json.count;
    

    EDIT:

    More explanation about local variables vs. ivars vs. properties…

    When you declare this in your view controller’s @interface in the .h file:

    NSArray *json;
    

    you are creating in instance variable (ivar) for your class. Whenever an instance of your class is instantiated it will have a member variable named json that you can access within the methods of your class.

    When you declare a property like this:

    @property (nonatomic, retain) NSArray *json;
    

    and a matching @synthesize in the implementation file:

    @synthesize json;
    

    the compiler auto generates a setter and getter method for you, so you can then use these methods:

    NSArray *theArray = [self json]; // getter
    [self setJson:newArray];         // setter
    

    You can do the same in modern Objective-C using dot notation:

    NSArray *theArray = self.json; // getter
    self.json = newArray;          // setter
    

    Your property ends up being backed by an ivar, which is by default named the same of the property and will be autogenerated for you if it doesn’t exist. (You can also specify the name of the backing ivar in the @synthesize statement, and you’ll often see people using ivar names that start with an underscore to help keep straight what is the ivar name and what is the property name, but I won’t go into that further here)

    Your object’s properties can be accessed from other classes, whereas your object’s ivars cannot.

    But back to your question. In addition to your ivar and property, you have created a local variable, also named json in your fetchedData: method. This variable, because you declare it within the body of the method, will only exist until the method finishes, at which time it will be deallocated and the data contained will be lost if not retained elsewhere. Because you have given your local variable the same name as your ivar, the local variable effective hides the ivar.

    Apple does not recommend using ivars directly anyway, but instead doing all access through your class properties (getter and setter methods). That’s why I suggested using self.json. It should also fix your problem, since values saved to your property will persist beyond the execution of the method.

    Hope that helps some.

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

Sidebar

Related Questions

I am having hard time getting hasErrors to work with indexed properties. For example
I am having hard time finding a way to display a loading image in
I'm having hard time getting my head wrapped around this one - and it
I'm having hard time getting this snippet to work. I have made a minimal
I'm having hard time deciding which name to choose for my method. I think
I am having hard time to understand how to make field value unique while
The reason why I am having a hard time populating this table is because
Im having hard time to understand the advantages of callback on the basic way
Hehe I'm having hard time on choosing the question title. But let me explain
I'm having hard time trying to figure out how to auto-save user data in

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.