89

うまくいけば、これは迅速な修正になるでしょう。私は取得し続けるエラーを理解しようとしています。エラーは以下にリストされており、appdelagate はその下にあります。

どんな助けでも大歓迎です。

ありがとう

2012-04-12 21:11:52.669 Chanda[75100:f803] --- でのアサーションの失敗-[UITableView _endCellAnimationsWithContext:]/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037 2012-04-12 21:11:52.671 Chanda[75100:f803] --- 例外がキャッチされていないため、アプリを終了しています ' NSInternalInconsistencyException' 、理由: '無効な更新: セクション 0 の行数が無効です。更新後の既存のセクションに含まれる行数 (2) は、更新前にそのセクションに含まれる行数 (2) に等しい必要があります。またはそのセクションから挿入または削除された行数 (1 挿入、0 削除) と、そのセクションに移動した行数またはそのセクションから移動した行数 (0 移動、0 移動) を差し引いた値。

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize databaseName,databasePath; 

- (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
    self.databaseName = @"Customers.db";

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDir = [documentPaths objectAtIndex:0];
    self.databasePath = [documentDir stringByAppendingPathComponent:self.databaseName];
    [self createAndCheckDatabase];

    return YES;
}

- (void)createAndCheckDatabase {
    BOOL success;

    NSFileManager *fileManager = [NSFileManager defaultManager];
    success = [fileManager fileExistsAtPath:databasePath];

    if (success) return; 

    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseName];

    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}

@end
4

12 に答える 12

43

コードのこの部分を見せてくれる理由がわかりません。エラーは、コードのこの部分に接続されている必要があります

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

おそらく、これらのデータ ソース メソッドのいずれかで間違いを犯している可能性があります。現在、正確に何が間違っているかを言うことは不可能ですが、次のようなものである可能性があると思います:たとえば、 n行を予約してセットアップしnumberOfRowsInSectionたいテーブルビューに伝え、次にn - 1行のみを処理します。cellForRowAtIndexPath

申し訳ありませんが、この回答は本来あるべきほど正確ではありません。データ ソースの実装を見せていただければ、何が起こっているかをより簡単に把握できます。

于 2012-06-14T07:50:47.073 に答える
25

行を削除するときは、更新時に次のセクションもチェックすることに注意してください。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView

セクションの最後の項目である行を削除したい場合は、代わりにセクション全体を削除する必要があります (そうしないと、セクション数が間違ってこの例外がスローされる可能性があります)。

于 2013-01-04T16:42:07.757 に答える
6

numberOfRowsInSection を決定する配列を更新することを忘れないでください。アニメーション化して削除する前に更新する必要があります

セクション全体を削除する必要があるため、セクションの行数が 1 かどうかを確認します。

誰かがこの答えをより明確にすることができれば、私を修正してください。

[self.tableView beginUpdates];
if ([tableView numberOfRowsInSection:indexPath.section] == 1) {

   [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
} else {

   [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
[self.tableView endUpdates];
于 2014-11-12T11:44:06.063 に答える
4

各セクション要素を別々の配列に入れました。次に、それらを別の配列に入れます(arrayWithArray)。この問題に対する私の解決策は次のとおりです。

[quarantineMessages removeObject : message];
[_tableView beginUpdates];
if([[arrayWithArray objectAtIndex: indPath.section] count]  > 1)
{
    [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indPath] withRowAnimation:UITableViewRowAnimationBottom];
}
else
{
    [_tableView deleteSections:[NSIndexSet indexSetWithIndex:indPath.section]
              withRowAnimation:UITableViewRowAnimationFade];
}
[_tableView endUpdates];
于 2013-03-29T11:48:34.753 に答える
2

私は同じエラーを抱えていましたが、試してみると[tableView reloadData]うまくいきました。エラーは実際には行にありました

[TabView insertRowsAtIndexPaths:indexPathsArray withRowAnimation:UITableViewRowAnimationRight];

indexPath の値を確認しようとしたところ、必要に応じて正しくありませんでした。

の値を変更して修正しましたindexPathsArray

お役に立てれば 。

于 2016-05-31T11:45:27.510 に答える
2

私のようなものを使用していてNSFetchedResultsController、バックグラウンド スレッドでデータを更新している場合は、デリゲートで更新を開始および終了することを忘れないでください。

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}
于 2016-01-22T23:59:51.090 に答える
1

UITableViewDataSourceプロトコルメソッドの1つである可能性があります

為に

- tableView:numberOfRowsInSection:

の合計または結果に等しい整数を返す必要があります。

-insertRowsAtIndexPaths:withRowAnimation:および/または-deleteRowsAtIndexPaths:withRowAnimation:

為に

- numberOfSectionsInTableView:

の合計または結果に等しい整数を返す必要があります。

-insertRowsAtIndexPaths:withRowAnimation:および/または -deleteSections:withRowAnimation:

于 2016-01-17T07:30:22.660 に答える
0

[yourTableView reloadData]; を呼び出していることを確認するだけです。値の配列を変更した後。

于 2016-04-07T14:26:45.743 に答える
0

Swift と FRC でバックアップされたデータ ストアを使用して情報を管理しているときに、これが発生しました。現在の indexPath.section を評価する単純なチェックを削除操作に追加することで、不要な呼び出しを回避できました。この問題が発生する理由を理解していると思います...基本的に、データセットが空の場合は常にメッセージを一番上の行にロードします。これにより、偽の行があるため、オフ バイ ワンの問題が発生します。

私の解決策

... delete my entity, save the datastore and call reloadData on tableView
//next I add this simple check to avoid calling deleteRows when the system (wrongly) determines that there is no section.

       if indexPath.section > 0 {

        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .None)

            }
于 2015-02-22T03:33:56.787 に答える
0

コア データベースでも同じ問題が発生しました。多くの FRC を使用している場合は、numberOfSectionsInTableView の各条件内でテーブルビューをリロードするだけです。

于 2013-10-30T04:39:03.887 に答える