2011-02-16 7 views
0

保存しないFOR EDIT、//理由を新しいデータココアエラーを保存しない>coredata sqliteのインポートが、256

は私が編集し保存した後、(pleseはコードの下で確認してください)私のSaveDataをして、いくつかのNSLogを入れて、新しい保存しましたデータ編集用 は、 罰金が、新しいが,,私は私が最初に時間を編集して保存した場合、それは細かい編集したデータを保存します>

Error The operation couldn’t be completed. (Cocoa error 256.) 

**第二編集> 得るが、ショーのためにあります新しいデータの場合はエラー256、

私は256のエラー(新しいデータを保存しようとすることによって)をした後に編集したデータを保存しようとすると、編集したデータは保存時にエラー256を表示し、保存されません!!!!

イムいくつかのsqlitedb

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 
    if (persistentStoreCoordinator_ != nil) { 
     return persistentStoreCoordinator_; 
    } 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"ChildCare_v02.sqlite"]; 

    NSString *storePath = [[NSBundle mainBundle] pathForResource:@"ChildCare_v02" ofType:@"sqlite"]; 

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ChildCare_v02.sqlite"]; //este es el que sirve!!! CREE ESTE 

    NSLog(@"store URL %@", storeURL); 

    // Put down default db if it doesn't already exist 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    if (![fileManager fileExistsAtPath:writableDBPath]) { 
     NSLog(@"proceda aqui"); 
     NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"ChildCare_v02" ofType:@"sqlite"]; 
     NSLog(@"no existe todavia"); 
     NSLog(@"defalultStorePath %@", defaultStorePath); 

     if (defaultStorePath) { 
      [fileManager copyItemAtPath:defaultStorePath toPath:writableDBPath error:NULL]; 
      NSLog(@"storePath= %@", storePath); 
     } 
    }  

    NSError *error = nil; 
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 

     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    }  
    return persistentStoreCoordinator_; 
} 

それは私がデータを編集するとき、新しいデシベル罰金作成し、既存のデータを移入(coredataは、いくつかの事前入力のテーブルではなく発生していることと同じ)を(事前に設定)をインポートアプリでは、このデータを保存します(sqliteマネージャーでシミュレーター文書にチェックインして外に出ています)。しかし、新しいエントリーを作成すると、データを示す表に表示されますが、そして、この新しく作成されたエントリーはそこにはありません(もちろん、sqliteの新しいデータベースにはありません)...

これは私が保存用に使用するコードです編集したデータまたは新たに作成したデータを保存するので、そのことを可能に新しく作成されたデータ、

-(IBAction)saveData 
{ 
    if(editFlag==1) 
    { 
     NSManagedObjectContext *context = [(ChildCare_v01AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 

     NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; 
     NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:context]; 
     [request setEntity:entity]; 

     editEmp.namemployee = tfName.text; 
     editEmp.surname = tfSurname.text; 
     editEmp.email = tfEmail.text; 
     //editEmp.phone = tfPhone.text; 
     editEmp.mobile = tfMobile.text; 

     editEmp.category=tfCategory.text; 

     NSLog(@"salvado editado"); //saving FINE!!!!   

     NSError *error; 
     if (![context save:&error]) 
     { NSLog(@"Error %@",[error localizedDescription]); } 
     //[context release]; 

     [self.navigationController popViewControllerAnimated:TRUE]; 

    } 
    else{ 
     NSManagedObjectContext *context = [(ChildCare_v01AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
     Employee *employee = (Employee*)[NSEntityDescription 
             insertNewObjectForEntityForName:@"Employee" 
             inManagedObjectContext:context]; 
     employee.namemployee = tfName.text; 
     employee.surname = tfSurname.text; 
     employee.email = tfEmail.text; 
     //employee.phone=tfPhone.text; 
     employee.mobile = tfMobile.text;  
     employee.category=tfCategory.text; 

     NSLog(@"salvado nuevo"); ///HERE THE ERROR!! COCOA ERROR 256!!!!  

     NSError *error; 
     if (![context save:&error]) { 
      NSLog(@"Error %@",[error localizedDescription]); 
      // handle error 
     } else { 
      NSLog(@"Done"); 
     } 
     [self.navigationController popViewControllerAnimated:TRUE]; 

    } 
} 
  • ?なぜ動作していないのですか?編集内容を保存するのはなぜですか?新しいデータはありませんか?これを達成するのを手伝ってください、ありがとうございます!
+1

エラーが発生したときにエラーのuserInfoをダンプします。 'NSLog(@" Error%@ [%@] "、[error localizedDescription]、[error userInfo]);これは、エラーの理由についての詳細情報を提供します。 –

答えて

0

試してみること: 1.保存する前にmanagedObjectContextにnull以外の値が設定されていることを確認してください。 2. db初期化コードが元のデータベースを再インストールしています(変更が失われています)? 幸運。

+0

お返事ありがとうございます。番号1を確認していただきありがとうございます。私がチェックしたときに編集します。元のデータベースは再インストールされていません。編集時に行った変更は保存されています(sqlite manager、元のデータでは元のデータは同じままですが、シミュレータフォルダのsqliteでその編集用のデータが保存されます) – MaKo

+0

数字1、「スクラッチパッドは空ではありません」と打った後のデータを見ることができます保存...しかし、アプリを離れるとき、データはもう存在しません。 – MaKo

+0

persistenStoreCoordinatorメソッドで、毎回呼び出されるこのコードではありませんか?それはDBを上書きしませんか? if(defaultStorePath){ [ファイルマネージャーcopyItemAtPath:defaultStorePath toPath:writableDBPathエラー:NULL]; NSLog(@ "storePath =%@"、storePath); } } – Rayfleck

関連する問題