0
我遇到了这个问题,我已经遍及互联网搜索,仍然无法找到解决方案。请看下面的代码:UITableView异常当滚动和添加单元格
NSLog(@"%i", [self tableView:tableView numberOfRowsInSection:0]); // 4
[self updateCardIDArray];
NSLog(@"%i", [self tableView:tableView numberOfRowsInSection:0]); // 5
int indexOfCreatedCard = [cardIDs indexOfObject:newCardID];
NSLog(@"%i", indexOfCreatedCard); // 4
[tableView reloadData];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexOfCreatedCard inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:FALSE];
NSArray *insertIndexPaths = [[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:indexOfCreatedCard inSection:0], nil];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationRight];
基本上,我想在这里实现的是滚动表刚刚创建的单元格,然后显示它正在添加动画当我使用此代码,我。有这样的错误:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070
与此异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.
的事情是,如果我删除滚动和重装数据线,该计划将正常工作(不能够看到附加细胞动画,当然)。任何帮助将不胜感激!
我在滚动之前调用了[tableView reloadData],应该在tableView滚动之前添加单元格。我试图插入,然后滚动,应用程序不会崩溃。虽然,插入动画无法看到,这不是我想要实现的。 – user945711
使用[aTableView beginUpdates];和[aTableView endUpdates];为动画插入并设置aTableView.contentInset = UIEdgeInsetsMake(0,0,10,0);调整“contentInset”底部空间中的值以查看动画看到我更新的代码,您可能需要更改“contentInset”值 –
我添加了更改内容的插入代码,现在它只在新单元格之前滚动到右侧,这些内容插入代码,它直接滚动到添加的单元格,但没有动画。问题是,如果新单元格在屏幕上(内容大小小于高度),则会显示动画。 – user945711