I have a problem with populating the data from NSMutableArray to UITableView. In the ViewDidLoad, I did a network call which gets data from Parse and return an NSMutableArray called 'journalEntries' then I copied the data in this array to the NSMutableArray variable called 'allEntries'. I set a breakpoint here and verified that _allEntries has 4 objects (not nil). However, when it comes to numberOfRowsInSection method, _allEntries.count returns 4 but I set a breakpoint here and all the objects in _allEntries becomes nil.
- (void)viewDidLoad {
[super viewDidLoad];
_allEntries = [[NSMutableArray alloc] init];
[MMDatabaseHelper getAllJournalEntries:^(NSMutableArray *journalEntries) {
for (MMJournalEntry *entry in journalEntries)
[_allEntries addObject:entry];
// I set a breakpoint here and verified that _allEntries has 4 objects
[self.tableView reloadData];
}];
This method below returns 4 but all the objects in the allEntries array are nil. They weren't nil in the viewDidLoad.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _allEntries.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
MMJournalEntry *currentEntry = _allEntries[indexPath.row];
return cell;
}
Edit 1: The first screenshot is when the network call is done. The second is when it comes to the numberOfRowsInSection method

Edit 2: This is getAllJournalEntries method
+(void) getAllJournalEntries:(void(^)(NSMutableArray *journalEntries))callback {
PFQuery *query = [PFQuery queryWithClassName:JournalTable];
[query findObjectsInBackgroundWithBlock:^(NSArray *entries, NSError *error) {
if(entries != nil && entries.count > 0) {
NSMutableArray *mainEntries = [[NSMutableArray alloc] init];
for (PFObject *entry in entries) {
//convert to journal entry...
MMJournalEntry *je = [[MMJournalEntry alloc] init];
je.objId = entry.objectId;
je.textContent = entry[@"textContent"];
je.createdByUserId = entry[@"createdByUserId"];
je.cityStateName = entry[@"cityStateName"];
je.lattitude = entry[@"lattitude"];
je.longitude = entry[@"longitude"];
je.lattitude = entry[@"lattitude"];
je.tags = [NSMutableArray arrayWithArray:[entry[@"tags"] componentsSeparatedByString:@","]];
je.numberOfHearts = entry[@"numberOfHearts"];
[mainEntries addObject:je];
}
callback(mainEntries);
}
else
callback(nil);
}];
}

NSArray(orNSMutableArray) cannot benil. If you are seeing the "objects" in_allEntriesasnil, there is something wrong with your debugger or your interpretation of its output. - Ian MacDonald_allEntries? If it's a @property of the viewController, maybe tryself.allEntriesinstead? Shouldn't access the backing ivar directly anyway. Also if you're trying to access the entry for row #10 for example but you only have 5 entries, there is no value for that array index. Would be a good idea to confirm that entry exists anyway. - mc01(null)). It's illegal for there to be nil entries in an NSArray. - Hot LicksgetAllJournalEntries:call its completion handler on? It's easy to imagine thatreloadDatawouldn't work from a background queue. In that case your assumption that-tableView:numberOfRowsInSection:is called after-viewDidLoadwouldn't necessarily stand up. - TommyMMJournalEntryobject - in particular its property declarations - it looks like they are being released - Paulw11