0

わかりましたので、私はアプリのテストの最終段階にあり、今、私を困惑させる問題に遭遇しました.

プロセスは次のとおりです。

1)coredataを介してmyTableView、firstViewControllerでリンクされている「メインテーブル」に変更します

2) 上記のコードの一部として、以前のすべてのオブジェクトを削除し、文字列を「同期ログ テーブル」に保存しています。結果として、このテーブルには 1 つのオブジェクト ("Mon 20:33" などの文字列) を残す必要があります。 注: これは新しく実装された機能であり、問​​題の原因であると考えています。すべてのデバイスにラベルを入力して、最後に同期されたデータを表示するために使用しているため、つまり、ユーザーに簡単にすべてのデバイスに同じ情報があり、最新であることを確認してください

3)両方の変更は、呼び出しによって保存されます[managedObjectContext save:&error];

4) 2 番目のデバイスでは、すべて正常に動作しておりmyTableView、コードを呼び出してリロードした後に表示される「メイン テーブル」を更新できます。

2 番目のデバイスに 3 つの行が表示されていることに注意してくださいmyTableView。ステップ 1 で「メイン テーブル」に加えた変更は、結果をフィルタリングする述語のため、2 番目のデバイスのテーブルビューを変更しません。

それから問題が始まります

5) 2 番目のデバイスは、iCloud とデリゲート メソッドを介して変更を受信し始めます。

- (void)mergeiCloudChanges:(NSNotification*)note forContext:(NSManagedObjectContext*)moc {
NSLog(@"AppDelegate Merge icloud changes for context");
 //***Specifically the line below!!
[moc mergeChangesFromContextDidSaveNotification:note]; 

NSNotification* refreshNotification = [NSNotification notificationWithName:@"RefreshAllViews" object:self  userInfo:[note userInfo]];

[[NSNotificationCenter defaultCenter] postNotification:refreshNotification]; 
}

上記のコードの行は、firstViewController で次のメソッドを開始します

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"I'm inside the method Controller Will Change Context");
[self.myTableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
   atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
  newIndexPath:(NSIndexPath *)newIndexPath {
NSLog(@"I'm inside the method Controller did Change Object");

UITableView *tableView = self.myTableView;

switch(type) {
        // And enters in this line here
    case NSFetchedResultsChangeInsert:
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
        break;

    case NSFetchedResultsChangeDelete:
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
        break;

    case NSFetchedResultsChangeMove:
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
        [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
        break;
   }
}

次に、エラーが発生します。

CoreData: error: Serious application error.  
An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  
Invalid update: invalid number of rows in section 0.  
The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

このエラーを受け取った後、myTableView は応答しなくなります。たとえば、更新したり、スワイプによる削除に応答したりしません。

基本的に私の理解では、「同期ログ テーブル」からマージされているオブジェクトは、「メイン テーブル」からのみオブジェクトを受け取る必要がある myTableView デリゲート メソッドに挿入されているため、カウントとエラーの原因。

私の状況でこれを解決する方法はありますか?どんな助けでも大歓迎です

4

1 に答える 1

0
于 2012-06-01T10:38:07.913 に答える