2012-07-26 11 views
31

テーブルビューのセルでアニメーションを使用しています...セルが完全に表示されているとアニメーションが正常に動作しています。 [_Mytableviewobject endUpdates]行でクラッシュしました。セルアニメーションの停止分数は開始分数よりも大きい必要があります

クラッシュログ=キャッチされない例外によりにアプリを終了「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); 
} 

答えて

26

はい、私もこの顔1つの問題だけでフッタービューを削除してください。

+0

ありがとうございました。今働いています –

+24

説明していないのはなぜ?私はスクロール時(スクロール時のみ行を削除または追加しない)と同じ例外があり、それはPITAです。 – Cyrille

+0

提案された解決策は私にとってはうまくいきません。なぜ誰かがこのソリューションがなぜ機能するのか説明できれば助かります – wuf810

5

のそのヘッダーを使用する空のセクション

  • を作成し、私は同じことを持っていましたios 7アップデート後の問題:テーブルビューの展開/折りたたみのための「deleteRowsAtIndexPaths」中にクラッシュが発生しました。

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

     
    -(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 
    } 
    
    

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

  • +0

    テーブルビューの展開と折りたたみのデモコードを送ってください –

    +2

    これは私のために働いたものです。理由は分かりません。ちょうどiOS 7のバグです。 –

    +1

    これはリストの上位にあるはずです。これは実際にはOSのバグであり、バグはセクションのフッター(ヘッダーではない)にしか関係しません。だから私たちのセクションディバイダを持っている必要があります、解決策は、フッターの代わりにヘッダーを使用することです。おそらく理想的ではありませんが、ここで提案されている他のオプションよりも優れています(tableViewフッターを使用し、セクションフッターなどを取り除きます)。 –

    3

    iOS 7のアップデート後にこの問題が発生した場合: セクションのフッタービューのビューフレームを確認してください。それがtableviewセルと重なっている場合。システムはこの例外をスローします。

    +0

    iOS 7.0,7.0.1,7.0.2の本当のバグだと思います。それはiOS 7.0.3で修正されているようです。 –

    +1

    いいえ、これはまだ7.0.3の後に存在します。少なくとも7.1,7.1.1および7.1.2以降 – DonnaLea

    44

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

    ソリューションは

    tableView:viewForFooterInSection: 
    tableView:heightForFooterInSection: 
    

    を取り除くとのviewDidLoadで、次のように置き換えることでした:

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

    これは完璧な解決策です!完全に動作し、空のセルを完全に隠すことができます。どうもありがとうございます! – sridvijay

    +0

    溶液のためのThanx!それはiOS7で動作します – somedev

    +0

    良い解決策...:D – duongvanthai

    6

    tableview

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

    しばらくを設定すると起こるように思われますtableviewGroupedの代わりにスタイルをPlainに設定します。 tyle

    2

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

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

    また、私のために働いた残念なことに、この修正は、tableviewのコンテンツサイズがそれよりも大きい場合にのみ機能します。 – Lukas

    3

    これはiOSのバグです。私はバグレポートを提出し、彼らは14898413の複製を言って帰ってきました。このバグは、まだAppleのバグ報告者に公開としてマークされています。修正のための

    オプション: 1)フッタ 2を削除)する代わりに、行を削除するので、開始と終了の更新は、私が最後のセクションのためのreloadDataを()を呼び出すことによって、このバグを解決し、テーブルに

    0

    をリロード:

    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() 
         } 
        } 
    } 
    
    0

    私は同じ問題を経験しました。例外は、[[self tableView] endUpdates]で 'Cell animation stop fractionはstart fractionより大きくなければなりません。私は例外をキャッチし、endUpdatesを2回目にして解決しました。

    [[self tableView] beginUpdates]; 
    @try 
    { 
        [[self tableView] endUpdates]; 
    } 
    @catch (NSException* exception) 
    { 
        [[self tableView] endUpdates]; 
    } 
    
    +0

    これはクラッシュを回避しましたが、レイアウトが誤っていました。 – ohnit

    関連する問題