Ios5 单元动画停止分数必须大于开始分数

Ios5 单元动画停止分数必须大于开始分数,ios5,Ios5,我正在表格视图单元格中使用动画…当单元格完全可见时,动画工作正常。如果由于动画原因,任何单元格当时部分可见,我的应用程序将在第[_MyTableViewObjectEndUpdates]行崩溃 崩溃日志=由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“单元动画停止分数必须大于开始分数” 代码部分: -(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionO

我正在表格视图单元格中使用动画…当单元格完全可见时,动画工作正常。如果由于动画原因,任何单元格当时部分可见,我的应用程序将在第[_MyTableViewObjectEndUpdates]行崩溃

崩溃日志=由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“单元动画停止分数必须大于开始分数”

代码部分:

-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
{
     //ENSLog(self, _cmd);
    [_caseTable reloadData];
    NSInteger countOfRowsToInsert = 1;
    SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionOpened];
    sectionInfo.open = YES;


    NSMutableArray *indexPathsToInsert = [[[NSMutableArray alloc] init] autorelease];
    for (NSInteger i = 0; i < countOfRowsToInsert; i++) 
    {
        [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
    }

    NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
    NSInteger previousOpenSectionIndex = self.openSectionIndex;
    if (previousOpenSectionIndex != NSNotFound)
    {
        SectionInfo *previousOpenSection = [self.sectionInfoArray objectAtIndex:previousOpenSectionIndex];
        previousOpenSection.open = NO;
        [previousOpenSection.headerView toggleOpenWithUserAction:NO];
        NSInteger countOfRowsToDelete = 1;
        for (NSInteger i = 0; i < countOfRowsToDelete; i++)
        {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
        }
    }

    // Style the animation so that there's a smooth flow in either direction.
    UITableViewRowAnimation insertAnimation;
    UITableViewRowAnimation deleteAnimation;
    if (previousOpenSectionIndex == NSNotFound || sectionOpened < previousOpenSectionIndex) 
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationBottom;
    }
    else
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationTop;
    }

    // Apply the updates.
    [_caseTable beginUpdates];
    [_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
    [_caseTable insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation];
    [_caseTable endUpdates];
    //ExNSLog(self, _cmd);

    self.openSectionIndex = sectionOpened;
    //ExNSLog(self, _cmd);

}




-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)sectionClosed
{
     //ENSLog(self, _cmd);
    SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionClosed];
    sectionInfo.open = NO;
    NSInteger countOfRowsToDelete = [_caseTable numberOfRowsInSection:sectionClosed];
    if (countOfRowsToDelete > 0)
    {
        NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
        for (NSInteger i = 0; i < countOfRowsToDelete; i++) 
        {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
        }
        [_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
    }
    self.openSectionIndex = NSNotFound;
     //ExNSLog(self, _cmd);
}
-(无效)sectionHeaderView:(sectionHeaderView*)sectionHeaderView SectionOpen:(NSInteger)SectionOpen
{
//ENSLog(self,_cmd);
[_casetablereloaddata];
NSInteger ROWSTOINSERT计数=1;
SectionInfo*SectionInfo=[self.sectionInfoArray对象索引:SectionOpen];
sectionInfo.open=是;
NSMutableArray*indexPathsToInsert=[[NSMutableArray alloc]init]autorelease];
对于(NSInteger i=0;i0)
{
NSMutableArray*indexPathsToDelete=[[NSMutableArray alloc]init]autorelease];
对于(NSInteger i=0;i
是的,我也面临这类问题,只需删除页脚视图即可。

您可以使用下一节的页眉 我的答案也在这里

  • 创建空节
  • 使用其页眉而不是页脚

在ios 7更新之后,我遇到了同样的问题:在我的表视图中展开/折叠内容的“deleteRowsAtIndexPaths”过程中出现崩溃

令人惊讶的是,我通过使用heightForHeaderInsection而不是heightForFooterInSection解决了这个问题

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 1; // it was 0 before the fix } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0; // it was 1 before the fix } -(CGFloat)表格视图:(UITableView*)表格视图头部高度部分:(NSInteger)部分{ 返回1;//在修复之前为0 } -(CGFloat)表视图:(UITableView*)表视图页脚高度:(NSInteger)部分{ 返回0;//修复之前为1 }
此问题已报告()。

对于在iOS 7更新后遇到此问题的人员:
检查剖面页脚视图的图幅。如果它与tableview单元格重叠。系统抛出此异常。

在尝试使用伪页脚删除潜在的“空”表视图单元格时,我遇到了相同的崩溃

解决的办法是摆脱

tableView:viewForFooterInSection:
tableView:heightForFooterInSection:
并在viewDidLoad中将其替换为以下内容:

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

设置
tableview

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

tableview
style set
Plain
而不是
Grouped
style

时,每当我滚动到tableview的底部并尝试删除单元格和插入节时,我都会遇到相同的错误和崩溃,我的解决方案是在调用
[tableview beginupdates]之前将tableview滚动回顶部
使用TableView内容偏移量。使用这个解决方案,我根本不需要更改我的节头或节尾

[self.tableView setContentOffset:CGPointZero animated:NO];

这是iOS中的一个bug。我提交了一份bug报告,他们回来说这是14898413的副本。这个bug仍然在apple bug reporter中标记为打开

修复选项: 1) 删除页脚
2) 不是删除行,而是开始和结束更新重新加载表

我通过为最后一节调用reloadData()解决了这个错误:

-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
{
     //ENSLog(self, _cmd);
    [_caseTable reloadData];
    NSInteger countOfRowsToInsert = 1;
    SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionOpened];
    sectionInfo.open = YES;


    NSMutableArray *indexPathsToInsert = [[[NSMutableArray alloc] init] autorelease];
    for (NSInteger i = 0; i < countOfRowsToInsert; i++) 
    {
        [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:sectionOpened]];
    }

    NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
    NSInteger previousOpenSectionIndex = self.openSectionIndex;
    if (previousOpenSectionIndex != NSNotFound)
    {
        SectionInfo *previousOpenSection = [self.sectionInfoArray objectAtIndex:previousOpenSectionIndex];
        previousOpenSection.open = NO;
        [previousOpenSection.headerView toggleOpenWithUserAction:NO];
        NSInteger countOfRowsToDelete = 1;
        for (NSInteger i = 0; i < countOfRowsToDelete; i++)
        {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
        }
    }

    // Style the animation so that there's a smooth flow in either direction.
    UITableViewRowAnimation insertAnimation;
    UITableViewRowAnimation deleteAnimation;
    if (previousOpenSectionIndex == NSNotFound || sectionOpened < previousOpenSectionIndex) 
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationBottom;
    }
    else
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationTop;
    }

    // Apply the updates.
    [_caseTable beginUpdates];
    [_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];
    [_caseTable insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:insertAnimation];
    [_caseTable endUpdates];
    //ExNSLog(self, _cmd);

    self.openSectionIndex = sectionOpened;
    //ExNSLog(self, _cmd);

}




-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)sectionClosed
{
     //ENSLog(self, _cmd);
    SectionInfo *sectionInfo = [self.sectionInfoArray objectAtIndex:sectionClosed];
    sectionInfo.open = NO;
    NSInteger countOfRowsToDelete = [_caseTable numberOfRowsInSection:sectionClosed];
    if (countOfRowsToDelete > 0)
    {
        NSMutableArray *indexPathsToDelete = [[[NSMutableArray alloc] init] autorelease];
        for (NSInteger i = 0; i < countOfRowsToDelete; i++) 
        {
            [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:sectionClosed]];
        }
        [_caseTable deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
    }
    self.openSectionIndex = NSNotFound;
     //ExNSLog(self, _cmd);
}
func expandSectionPressed(sender: UIButton) {
    let object = items[sender.tag]
    object.expanded = !object.expanded
    sender.selected = object.expanded
    var indexPaths = [NSIndexPath]()
    for i in 0..<7 {
        indexPaths.append(NSIndexPath(forRow: i, inSection: sender.tag))
    }
    if object.expanded {
        tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Fade)
    } else {
        // strange crash when deleting rows from the last section //
        if sender.tag < numberOfSectionsInTableView(tableView) - 1 {
            tableView.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: .Fade)
        } else {
            tableView.reloadData()
        }
    }
}
func expandsection按下(发送方:ui按钮){
let object=items[sender.tag]
object.expanded=!object.expanded
sender.selected=object.expanded
var indexpath=[NSIndexPath]()

对于0中的i..我在[[self tableView]endUpdates]中遇到了相同的问题-异常“单元动画停止分数必须大于开始分数”;我通过捕获异常并再次进行endUpdates解决了此问题

[[self tableView] beginUpdates];
@try
{
    [[self tableView] endUpdates];
}
@catch (NSException* exception)
{
    [[self tableView] endUpdates];
}
这不能解释为什么,我也得了同样的e