繁体   English   中英

insertRowsAtIndexPaths断言失败

[英]assertion failure with insertRowsAtIndexPaths

我遇到这个错误:

Assertion failure in -[UITableView _endCellAnimationsWithContext:]

当我尝试使用insertRowsAtIndexPaths:withRowAnimation:

基本上我有一个带有对象的NSMutableArray ,称之为self.objects

我像这样添加对象:

MyObject *something = [MyObject new];
[self.objects addObject:something];

NSInteger count = self.objects.count;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:count];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

需要注意的是,我使用section而不是row来实现单元格间距。

更新

错误信息:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.30.14/UITableView.m:1704

数据源方法:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.objects count];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

起作用的代码:

MyObject * something = [MyObject new];

[self.objects addObject:something];

NSInteger计数= self.objects.count;

[self.tableView insertSections:[NSIndexSet indexSetWithIndex:count-1] withRowAnimation:UITableViewRowAnimationAutomatic];

描述:

在表格视图实施中,您将一行用于覆盖率部分。 并且您尝试将行插入到不可用(创建)的部分中。 因此,您必须首先插入仅可以插入行的部分(在您的实现中,每个部分只有一行,因此只能插入该部分)。

这将是

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:count-1];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM