2

iPhone SDKObjective-Cを使用していますが、次のエラー メッセージが表示されます。

-[UITableView _endCellAnimationsWithContext:]、/SourceCache/UIKit/UIKit-984.38/UITableView.m:774 2010-01-08 13:24:16.842 MyAPP[628:20b] でのアサーションの失敗 キャッチされない例外 'NSInternalInconsistencyException' によるアプリの終了理由: '無効な更新: セクション 1 の行数が無効です。更新後の既存のセクションに含まれる行数 (1) は、更新前にそのセクションに含まれる行数 (0) にプラスまたはそのセクションから挿入または削除された行数を引いたもの (0 挿入、0 削除)。

セクションを展開するコードは次のとおりです。

- (void)checkAction:(id)sender
{
    //The button is added as subview on a view and the view is section header custom view
    UIButton *Button = (UIButton*)sender;
    NSLog(@"Button Tag=%d",Button.tag);
    if([[self.MySectionIndexArray objectAtIndex:Button.tag] isEqualToString:@"UP"])
    {
        [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"DOWN"];
        [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Up.png"] forState:UIControlStateNormal];
        [TableDashBoard reloadSections:[NSIndexSet indexSetWithIndex:Button.tag] withRowAnimation:UITableViewRowAnimationFade];
    }
    else
    {
        [self.MySectionIndexArray replaceObjectAtIndex:Button.tag withObject:@"UP"];
        [ButtonDrop setBackgroundImage:[UIImage imageNamed:@"Down.png"] forState:UIControlStateNormal];
    }
    NSLog(@"self.MySectionIndexArray ka title = %@ at index Number=%d",self.MySectionIndexArray,Button.tag);
}
4

2 に答える 2

6

問題はreloadSections、テーブルのdataSource内容を変更しながら を使用しているため、 を介して異なる数の行が報告されるためですtableView:numberOfRowsInSection:

から返されたものを確認してくださいUITableViewDataSource tableView:numberOfRowsInSection:。私の予想では、最初はセクション 1 に対して 0 を返しますが、 を呼び出すとreloadSections、セクション 1 に対して 1 を返します。

これが実際に当てはまる場合は、UITableViewメソッドbeginUpdatesinsertRowsAtIndexPaths:withRowAnimation:およびを使用できますendUpdates

于 2010-01-08T08:22:09.963 に答える
2

私も同様の問題を抱えていました。私はdataSourceを更新していると確信していました。

しかし、ついに私は実際に2つのセクションを変更しているのに、1つのデータソースのみを更新していることに気付きました。

于 2011-05-17T03:25:16.973 に答える