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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:36:42+00:00 2026-05-15T18:36:42+00:00

In an iPhone app I’m developing, I grab a set of data from a

  • 0

In an iPhone app I’m developing, I grab a set of data from a web service, store it in a mutable array for showing in a table, and also store it in core data as backup when there is no network.

My array is initialized in application:didFinishLaunchingWithOptions: as follows
tableArray = [[NSMutableArray alloc] initWithCapacity:100];
the array is then filled after viewDidLoad gets called, meaning the UITableView exists (verified by checking debugger), and just before reloadData is called, I have NSLog print out the contents of the array, and sure enough everything is there.

My problem is that after reloadData is called, tableArray becomes null, as shown by an NSLog in tableView:numberOfRowsInSection:.

I’m at a complete loss as to why this is happening, though I’ve only been programming in Cocoa for a few months and could easily be missing something obvious.

EDIT: Updated with basic code.

@interface MyAppDelegate : NSObject {
...
NSMutableArray *tableArray;
}
@property (nonatomic, retain) NSMutableArray *tableArray;
...
@end

@implementation MyAppDelegate
@synthesize tableArray

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    tableArray = [[NSMutableArray alloc] initWithCapacity:100];

    masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:[NSBundle mainBundle]];
    [masterViewController.tableView setDelegate:self];
    [masterViewController.tableView setDataSource:self];
    ...
}

A method called runWithNetwork is then called in masterViewController’s viewDidLoad:

- (void)runWithNetwork {
    ...
    NSArray *backpackArray = [[mainDict objectForKey:@"items"] objectForKey:@"item"];
    NSLog(@"%i", [backpackArray count]);
    for (int a=0; a<[backpackArray count]; a++) {
    NSDictionary *itemDict = [backpackArray objectAtIndex:a];
        NSString *ID = [[itemDict valueForKey:@"defindex"] stringValue];
        NSString *level = [[itemDict valueForKey:@"level"] stringValue];
        NSString *quality = [[itemDict valueForKey:@"quality"] stringValue];
        NSString *inventory = [[itemDict valueForKey:@"inventory"] stringValue];
        NSNumber *uid = [NSNumber numberWithInt:a];

        //Insert new
        myItem = [NSEntityDescription insertNewObjectForEntityForName:@"Backpack" inManagedObjectContext:managedObjectContext_];
        [myItem setValue:level forKey:@"level"];
        [myItem setValue:inventory forKey:@"inventory"];
        [myItem setValue:quality forKey:@"quality"];
        [myItem setValue:uid forKey:@"uid"];

        //Link to item db
        NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id == %@", ID];
        [fetch setEntity:[NSEntityDescription entityForName:@"GlobalItems" inManagedObjectContext:managedObjectContext_]];
        [fetch setPredicate:predicate];

        item = [[managedObjectContext_ executeFetchRequest:fetch error:nil] objectAtIndex:0];
        [myItem setValue:item forKey:@"item"];

        [tableArray addObject:[item valueForKey:@"name"]]; //a series of nsstrings

    }
    NSLog(@"%@, %i", tableArray, [tableArray retainCount]); // all strings are printed correctly here, retaincount is 1

    [masterViewController.tableView reloadData];
}

Then I go to my table methods:

- (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section {  
    NSLog(@"%@, %i", tableArray, [tableArray retainCount]);  //(null) printed, 0 for retaincount
    return [tableArray count];  //returns 0
}

The tableView is in the MasterViewController’s xib, and is linked up correctly there. It is only ever described in MasterViewController and is set up as an IBOutlet. tableArray is only described in MyAppDelegate.h and is not re-created anywhere else.

  • 1 1 Answer
  • 2 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-15T18:36:43+00:00Added an answer on May 15, 2026 at 6:36 pm

    As I said in my comment, it’s hard to figure out what exactly is wrong. But from my experience helping people on mailing lists and the like, the most common cause of a bug like this is having two different objects when you think you have one. For example, one instance is created in a nib and another is manually created in code elsewhere. It might be worth checking.

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

Sidebar

Related Questions

My iphone app downloads user specific data from our web server. How can I
My iphone app uses a SQLite database to store data. I have a table
developing iphone app, I have used a UIImageview and i have set an image
An iPhone app which I am creating generates reports from a Core Data database
My iPhone app will download a large amount of data from a remote server.
My iphone app getting json data from php server. 2 basic questions, just to
In iPhone App how to store UIImage converted into NSData to sqlite table in
On Iphone App start I start a background thread to receive some data from
My iPhone app relies on a vendor's XML feed to provide data. But that
My iPhone app will have read-only system data AND read/write user data (stored either

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.