开发者社区> 问答> 正文

uitableview loadmore点击加载更多的问题 400 请求报错 

我做了一个点击一行就加载更多,但是出现下面的错误。后来调试
到-(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];
    
     
}

展开
收起
kun坤 2020-05-29 10:14:40 460 0
1 条回答
写回答
取消 提交回答
  • 建议你通过增加data,然后reload你的tableview就可以 ######有可能是你对一个cell同时用了两次动画。比如,我之前是这样的。         [self.tableView reloadRowsAtIndexPaths:@[ reloadIndex,indexPath] withRowAnimation:UITableViewRowAnimationNone];
    但是,其实,reloadIndex跟indexPath是一样的。

    2020-05-29 14:17:54
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载