0

For my iPad project I need to be able to reload table rows. This is how it should works, depend on some "id" selected from a popupview, i need to be able to reload table rows, table rows are dynamics and has a UITextField in it. I tried to use [self.tableView reload] but for some reason it does not update the rows correctly. Something like UITextField placeholder owned by previous "id" does not change. What I have in mind is to remove all cells in that specific section and reload the table with the new "id". When i do this i got this exception:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted).'

The project code:

- (void)selectedArchiefID:(NSString *) value {
   [self.popOverController dismissPopoverAnimated:YES];

   // collects all available document indexfields
   int rowCount = [indexDefinities count];
   NSMutableArray *indexPaths = [[NSMutableArray alloc] init];

   for (int curIndex=0; curIndex < rowCount; curIndex++) {
       [indexPaths addObject:[NSIndexPath indexPathForRow:curIndex inSection:0]];
   }

   // deletes rows
   if ([indexPaths count] > 0) {
      [self.tableView beginUpdates];
      [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
      //[self.tableView deleteSections:0 withRowAnimation:UITableViewRowAnimationNone];
        [self.tableView endUpdates]; //crashes here
   }

   [self.tableView reloadData];
}

Any idea what i did wrong?

4

1 回答 1

0

看起来您忘记更改 tableview 的数据源的数据。

您不能只更改 tableview 布局。

如果要删除某个部分,则必须先从数据源中删除该部分。您可以通过删除 NSMutableArray (这是您的数据源)中的部分来轻松地做到这一点。

numberOfSectionsInTableView:或者你可以写一个大的 if then else 怪物,计算出在and中返回多少节(和行)tableView:numberOfRowsInSection:

不管你怎么做,但你必须在更新表格视图之前删除数据。


还有一件事,同时[self.tableView beginUpdates]; /*...*/ [self.tableView endUpdates];使用[self.tableView reloadData];一种方法通常是没用的。后者会杀死你从第一个获得的动画效果。

于 2011-02-23T08:22:23.837 回答