31

テーブルビューセルでアニメーションを使用しています...セルが完全に表示されている場合、アニメーションは正常に機能しています。

クラッシュ ログ = キャッチされない例外 '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);
}
4

10 に答える 10

44

ダミー フッターを使用して潜在的な「空」のテーブル ビュー セルを削除しようとすると、同じクラッシュが発生しました。

解決策は、取り除くことでした

tableView:viewForFooterInSection:
tableView:heightForFooterInSection:

viewDidLoad で、それらを次のように置き換えます。

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
于 2013-11-08T14:43:16.230 に答える
26

はい、私もこのタイプの問題に直面しています。フッタービューを削除するだけです。

于 2012-07-26T10:03:06.933 に答える
6

設定すると発生するようですtableview

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

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

スタイルの代わりにスタイルがtableview設定されている間PlainGrouped

于 2013-11-28T08:54:05.983 に答える
5

iOS 7 の更新後に同じ問題が発生しました。テーブル ビューの展開/折りたたみの「deleteRowsAtIndexPaths」中にクラッシュが発生しました。

驚いたことに、heightForFooterInSection の代わりに heightForHeaderInsection を使用してこの問題を解決しました。

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    1 を返します。// 修正前は 0 でした
}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    0 を返します。// 修正前は 1 でした
}

この問題は報告されています ( https://devforums.apple.com/message/795349 )。

于 2013-10-24T09:50:07.737 に答える
4

次のセクションのヘッダーを使用できます私の同じ答えはここにあります

  • 空のセクションを作成する
  • フッターの代わりにヘッダーを使用する

https://stackoverflow.com/a/12297703/788798

于 2012-09-06T10:13:34.770 に答える
3

iOS 7 の更新後にこの問題が発生した場合: セクション フッター ビューのビュー フレームを確認します。テーブルビューのセルと重なっている場合。システムはこの例外をスローします。

于 2013-10-28T20:29:05.583 に答える
2

テーブルビューの一番下までスクロールしてセルを削除し、セクションを挿入しようとすると、同じエラーとクラッシュが発生しました。私の解決策は[tableview beginsUpdates]、テーブルビューのコンテンツオフセットを使用して呼び出す前に、テーブルビューを一番上にスクロールすることでした。このソリューションでは、セクションのヘッダーやフッターをまったく変更する必要はありませんでした。

[self.tableView setContentOffset:CGPointZero animated:NO];
于 2014-03-05T00:35:12.027 に答える
0

私は同じ問題を経験しました - [[self tableView] endUpdates] の例外「セルアニメーションの停止部分は開始部分より大きくなければなりません」; 例外をキャッチし、endUpdates を 2 回目にすることで解決しました。

[[self tableView] beginUpdates];
@try
{
    [[self tableView] endUpdates];
}
@catch (NSException* exception)
{
    [[self tableView] endUpdates];
}
于 2014-09-17T07:31:54.063 に答える
0

最後のセクションで reloadData() を呼び出して、このバグを解決しました。

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()
        }
    }
}
于 2014-08-15T12:20:45.100 に答える