添加行后,UITableView添加重复行

时间:2014-07-23 09:57:47

标签: ios objective-c uitableview

当我在UITableView中添加新行时,会添加一个重复的行。第一行完美运行,第二行完美运行,但第三行是第二行的副本。

为什么会这样?

这是我的代码:

- (void)addExerciseToCustomTable 
{
   // save my parametr from DB
   [self saveExerciseInCacheTableApproach:_approach andRepeat:_repeat andWeight:_weight andTimer:_timer andIndex:_index]; 

   //update position in my TableView from db( 1....10)
   [self updatePositionInCustomViewForAddRow:[NSString stringWithFormat:@"%d", ([_exerciseForGroupWithSelect count] - 1) ]]; 

   _exerciseForGroupWithSelect = [self loadExerciseFromExerciseCacheWithGroup:groupExerciseId];
   //load new array after update position

  [_customExerciseTable beginUpdates];

  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:([_exerciseForGroupWithSelect count] - 1) inSection:0];
  [_customExerciseTable insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  [_customExerciseTable endUpdates];
}

1 个答案:

答案 0 :(得分:0)

解决了这个问题 - 在编辑我的表后我更新了我的数据库

现在 - 我加载我的nutablearray并与他合作,编辑完成后,将数组保存在DB中 这是完美的工作