• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 重新加载 tableview 时发生断言失败?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 11:36:17 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我遇到的错误:

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-3347.44.2.2/UITableView.m:1326
2015-10-26 11:38:49.473 huwai[1784:684487] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 0 from section 1, but there are only 1 sections before the update'
*** First throw call stack:
(0x2a94f0d7 0x390cec77 0x2a94efad 0x2b64fbc9 0x2e1771d7 0xe865f 0xe61db 0x2e12d9ef 0x2dfdcb1d 0x2e3f6811 0x2dfa5ad5 0x2dfa3a4f 0x2dfdaeed 0x2dfda7dd 0x2dfb09b5 0x2e2270ff 0x2dfaf3b7 0x2a91500f 0x2a914423 0x2a912aa1 0x2a85e6d1 0x2a85e4e3 0x321fa1a9 0x2e010445 0x11f44d 0x3969caaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
  1. 我正在使用第三方 tableview(即)TQMultistageTableView。

2.当此错误发生时,我正在从数组中删除值并再次重新加载表格 View ,在特定时间发生错误,因为它并非总是发生。

这是我的代码

我在这里创建第三方表格 View

  -(void)viewWillLayoutSubviews
    {

        if([[UIDevice currentDevice].model hasPrefix"iPad"])
        {
            self.mTableView = [[TQMultistageTableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.viewsub.frame.size.height)];
        }
        else if([[UIDevice currentDevice].model hasPrefix"iPhone"])
        {
            self.mTableView =[[TQMultistageTableView alloc] initWithFrame:CGRectMake(0, 0, self.viewsub.frame.size.width,self.viewsub.frame.size.height)];
        }
        self.mTableView.delegate = self;
        self.mTableView.dataSource = self;
        self.mTableView.clipsToBounds=YES;
        self.mTableView.tableView.clipsToBounds=YES;



    }

- (NSInteger)numberOfSectionsInTableViewTQMultistageTableView *)tableView
{

    return [arrOrder count];
}

- (NSInteger)mTableViewTQMultistageTableView *)tableView numberOfRowsInSectionNSInteger)section
{

    return 1;
}
#pragma mark row
- (UITableViewCell *)mTableViewTQMultistageTableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{



    ServiceChargeCell *cell;
  cell  = [[ServiceChargeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier"cell" forIndexPath:indexPath];
    NSLog(@"inside charge screen product array%@",arrOrder);
    NSInteger order=[productid integerValue];
    NSMutableDictionary *dic=[flow.dicOrder objectForKey(order)];
    cell.lblname.textColor=[UIColor whiteColor];
    cell.lblname.text=[NSString stringWithFormat"%@",[dic objectForKey"description"]];
    NSLog(@"this is lable name=%@",[NSString stringWithFormat"%@",[dic objectForKey"description"]]);
    NSLog(@"this is from label=%@",cell.lblname.text);

    return cell;



}
- (UIView *)mTableViewTQMultistageTableView *)tableView openCellForRowAtIndexPathNSIndexPath *)indexPath
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.width)];
    view.backgroundColor = [UIColor colorWithRed:187/255.0 green:206/255.0 blue:190/255.0 alpha:1];;
    return view;

}

#pragma mark - Table view delegate

- (CGFloat)mTableViewTQMultistageTableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath
{


    if([[UIDevice currentDevice].model hasPrefix"iPhone"])
    {
        return 40;
    }
    else
    {
        return 80;
    }
}
- (CGFloat)mTableViewTQMultistageTableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    if([[UIDevice currentDevice].model hasPrefix"iPhone"])
    {
        return 50;
    }
    else
    {
        return 50;
    }
}

在我的标题 View 中,我有一个按钮,而该按钮单击操作一些数据正在删除,我再次在这里重新加载表格 View 。

-(void)btnClick:(UIButton *)click
{
    if(click.selected==NO)
    {
        NSString *tag=[NSString stringWithFormat:@"%lu",(long)click.tag];
        int key=[tag intValue];
        NSMutableDictionary *dic=[flow.dicOrder objectForKey:@(key)];
        [flow removeOrder:dic];




    }
    [self.mTableView.tableView reloadData];



}

为什么在重新加载 tableview 时会发生这种错误?请任何人帮助我解决这个问题



Best Answer-推荐答案


我查看了 TQMultistageTableView,显然在点击 headerView 时,它包含删除或插入部分的逻辑。我不确定这个第三方的东西是如何工作的,但看起来在你修改数据之后,第三方 tableView 得到了某种数据不匹配,它试图删除一个不存在的行。

关于ios - 重新加载 tableview 时发生断言失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33339602/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap