OGeek|极客世界-中国程序员成长平台

标题: ios - 重新加载 tableview 时发生断言失败? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:36
标题: ios - 重新加载 tableview 时发生断言失败?

我遇到的错误:

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4