应用程序在tableview的reloadData方法上崩溃



调用[tableView reloadData]表视图的方法后,我的应用程序崩溃。这发生在删除表视图的单行(表视图默认删除行为)并调用[tableView reloadData]之后,然后就在这个代理numberOfSectionsInTableView应用程序崩溃并向我显示崩溃消息[UITableViewCell _setDeleteAnimationInProgress : ] : message sent to deallocated instance之后,我在谷歌上搜索了一下,但无法得到正常的响应。因此,如果有人面临这种崩溃,请帮助找出这个问题。下面是我的代码。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section==0)
        return [[dbSingleton sharedInstance] get_players_count];
    else if(section==1)
        return 0;
}
- (NSString )tableView:(UITableView )tableView titleForHeaderInSection:(NSInteger)section{
    if(section==0)
        return @"Player Detail";
    return nil;
}
- (UITableViewCellEditingStyle)tableView:(UITableView )tableView editingStyleForRowAtIndexPath:(NSIndexPath )indexPath{
    if(indexPath.section==1)
        return UITableViewCellEditingStyleNone;
    else
        return UITableViewCellEditingStyleDelete;
    }
}
-(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{
    return 44;
}

寻求回应。提前谢谢。

最后,我找到了解决方案。我做错的是,我在commitEditingStyle上调用方法reloadData,这意味着在删除行之前重新加载数据,正如This Thread的回答中提到的那样。我希望这也能帮助其他人。感谢您的参与。

[tableView Reload]产生崩溃,那么很确定数据源中存在问题,所以我认为在tableView部分添加断点,并检查您是否正确更新了数据源,否则会显示完整的崩溃消息。

最新更新