ios - NSMutableArray data went nil when UITableView loads -


i have problem populating data nsmutablearray uitableview. in viewdidload, did network call gets data parse , return nsmutablearray called 'journalentries' copied data in array nsmutablearray variable called 'allentries'. set breakpoint here , verified _allentries has 4 objects (not nil). however, when comes numberofrowsinsection method, _allentries.count returns 4 set breakpoint here , objects in _allentries becomes nil.

- (void)viewdidload {     [super viewdidload];      _allentries = [[nsmutablearray alloc] init];      [mmdatabasehelper getalljournalentries:^(nsmutablearray *journalentries) {          (mmjournalentry *entry in journalentries)              [_allentries addobject:entry];         // set breakpoint here , verified _allentries has 4 objects          [self.tableview reloaddata];     }]; 

this method below returns 4 objects in allentries array nil. weren't nil in viewdidload.

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     // return number of rows in 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: first screenshot when network call done. second when comes numberofrowsinsection method

pic1

pic2

edit 2: 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];             (pfobject *entry in entries) {                 //convert 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);     }]; } 

as receive nsmutablearray parse, why don't copy on nsarray? should redeclare allentries property , don't need forin loop.

_allentries = journalentries.copy; 

as nsarray not mutable, never lose values.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -