2014-09-25 106 views
0

声明失败我是一个业余充其量,并坚持在这个错误!当然简单的东西...在 - [UITableView _endCellAnimationsWithContext:

- (void)addTapped:(id)sender { 
TechToolboxDoc *newDoc = [[TechToolboxDoc alloc] initWithTitle:@"New Item" thumbImage:nil fullImage:nil]; 
[_itemArray addObject:newDoc]; 
//[self.tableView beginUpdates]; 

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_itemArray.count-1 inSection:0]; 
NSArray *indexPaths = [NSArray arrayWithObject:indexPath]; 
NSLog(@"%@",indexPath); 

[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; 

[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; 
[self performSegueWithIdentifier:@"MySegue" sender:self]; 

    //[self.tableView endUpdates]; 

它上线打破了说

[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; 

回答

3

您需要添加[UITableView beginUpdates][UITableView endUpdates]各地:

[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; 

从类参考:

注意当在由beginUpdates和endUpdates方法定义的动画 块中调用时调用此方法的行为。 UITableView 推迟行或段的任何插入,直到它处理了行或段的删除 。无论订购 的插入和删除方法调用如何,都会发生这种情况。这与插入 或删除可变数组中的项目不同,其中操作可能会影响 用于连续插入或删除 操作的数组索引。有关此主题的更多信息,请参阅批处理插入,删除, 以及表视图编程指南中的行和区域的重新加载,以获取iOS版本 。

+3

现在我得到了同样的错误,但断点是在endupdates而不是 – Jayrod7387 2014-09-25 15:52:05

+0

我有和Jayrod7387一样的问题。 – livingtech 2015-04-27 14:47:13

+2

在我的情况下,这是因为我不准确地计算/返回'numberOfRowsInSection'。 – livingtech 2015-04-27 14:51:28

0

我想你要插入的行中的tableView但不更新number of rows at section这就是为什么你在这个行业得到错误。因此,在插入行的同时,您还应该增加数组的数量或用于显示表视图中行数的任何内容。

0

就我而言,我使用了Parse,并删除了一些用户(其中​​之一是我的iPhone模拟器)。每次刷新tableView时都会出现此错误。

我刚刚从模拟器中删除了应用程序,并创建了一个新帐户,它的工作原理完美无瑕。

@ droppy的回答给了我一个错误的灯泡时刻!

希望能帮助别人。