objective c - Not saving data for some reason after call to insertRowToIndexPath in iOS -


i have uitableview in app have user add rows table. calling "insertrowatindexpath":

- (ibaction)addrow:(id)sender {      nsstring *theobjecttoinsert = [nsstring stringwithformat:@"row #: %lu", (unsigned long)[self.tabledata count]];     [self.tabledata addobject:theobjecttoinsert];     nslog(@"what count of collection? %lu", self.tabledata.count-1);     nsindexpath *newpath=[nsindexpath indexpathforrow:self.tabledata.count-1 insection:0];     [self.mytable insertrowsatindexpaths:@[newpath] withrowanimation:uitableviewrowanimationautomatic];     [self.mytable scrolltorowatindexpath:newpath atscrollposition:uitableviewscrollpositionbottom animated:yes];   } 

my problem i've discovered after adding necessary rows, not saving data think should. here method supposed store data:

- (void)saveaction {      //i iterate through entire uitableview tally data of rows     nsmutablearray *cells = [[nsmutablearray alloc] init];     (nsinteger j = 0; j < [self.mytable numberofsections]; ++j) {         (nsinteger = 0; < [self.mytable numberofrowsinsection:j]; ++i) {             if ([self.mytable cellforrowatindexpath:[nsindexpath indexpathforrow:i insection:j]]) {                 [cells addobject:[self.mytable cellforrowatindexpath:[nsindexpath indexpathforrow:i insection:j]]];             }         }     }      nslog(@"the number of table rows are: %lu", (unsigned long)[cells count]);    } 

for reason, prints out "4", though i've added more. can see i'm doing wrong?

why u save uitableviewcell in cells array? while u have datas in self.tabledata array. never store/access ui object, use datamodel.

and coming point, uitableview docs, cellforrowatindexpath returns nil if cell not visible. though have 10 cells, if 4 cells visible, method return nil remaining 6 cells.

- (nullable __kindof uitableviewcell *)cellforrowatindexpath:(nsindexpath *)indexpath;    // returns nil if cell not visible or index path out of range 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -