我做了一个点击一行就加载更多,但是出现下面的错误。后来调试
到-(void) appendTableWith:(NSMutableArray *)data这个方法的时候才报错,问下这个代码段那里错了?我附上代码,在末尾就是报错的代码。
发生的错误提示
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to create two animations for cell';
数据源是array,是空数据,每次点击cell就增加10个数据到displaytenarray,nDownLoad=0
array = [[NSMutableArray alloc]init];
displaytenarray = [[NSMutableArray alloc]init];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [displaytenarray count]+1;
}
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"moretag"];
UILabel *labelNumber = [[UILabel alloc] initWithFrame:CGRectMake(45, 10, 100, 20)];
labelNumber.text = @"获取更多";
[labelNumber setTag:1];
labelNumber.backgroundColor = [UIColor clearColor];
labelNumber.font = [UIFont boldSystemFontOfSize:16];
[cell.contentView addSubview:labelNumber];
moreCell = cell;
return moreCell; } (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (indexPath.row == [displaytenarray count] && nDownLoad < [array count]) {
return [self createMoreCell:tableView cellForRowAtIndexPath:indexPath];
}
else {
return [self creatNormalCell:tableView cellForRowAtIndexPath:indexPath];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==[displaytenarray count]) {
UITableViewCell * loadmorecell= [tableView cellForRowAtIndexPath:indexPath];
loadmorecell.textLabel.text=@"正在加载";
[self performSelectorInBackground:@selector(loadMore:) withObject:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; } -(void)loadMore:(NSIndexPath *)indexPath{
NSMutableArray * more = [[NSMutableArray alloc]init];
for (int i=0; i<10; i++) {
NSString * st = [array objectAtIndex: i];
[more addObject:st];
[displaytenarray addObject:st];
NSLog(@"%@",st);
}
[ self performSelectorOnMainThread : @selector (appendTableWith:) withObject :more waitUntilDone : NO ]; } -(void) appendTableWith:(NSMutableArray *)data
{
NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];
for (int i=0; i<[data count]; i++) {
NSIndexPath *newPath = [NSIndexPath indexPathForRow:[displaytenarray indexOfObject:[data objectAtIndex:i]] inSection:0];
[insertIndexPaths addObject:newPath];
}
[data removeAllObjects];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。