У меня есть UitableView в моем приложении, где у меня есть пользователь добавить строки в таблицу. Я делаю это, назвав «insertrowatindexpath»: < /p>
- (IBAction)addRow:(id)sender {
NSString *theObjectToInsert = [NSString stringWithFormat:@"Row #: %lu", (unsigned long)[self.tableData count]];
[self.tableData addObject:theObjectToInsert];
NSLog(@"What is the count of the 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];
}
< /code>
Моя проблема, которую я обнаружил, заключается в том, что после добавления необходимых строк я не сохраняю данные, как думаю. Вот метод, который должен хранить данные: < /p>
- (void)saveAction {
//I iterate through my entire UITableView to tally up the data from all of the rows
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (NSInteger j = 0; j < [self.myTable numberOfSections]; ++j) {
for (NSInteger i = 0; i < [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]);
}
< /code>
По какой -то причине это только печатает «4», хотя я добавил гораздо больше. Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/331 ... ath-in-ios