0

CoreDataプロジェクトの保存ボタンを作成しようとしていますが、通常は問題ありません。しかし今回は、SQLファイルに保存されていない(FireFoxでSQLiteを使用している)ことも、UITableViewにデータをプルバックすることもできません。

エラーや警告はありません。誰かが私の曇った日曜日の午後(ニュージーランド時間)の頭を手伝ってくれますか?

- (IBAction)saveDataAction:(id)sender
{
//Instantiating the Entity with a pointer and giving it a mission.
NSString *details = @"Details";
NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:details inManagedObjectContext:[self managedObjectContext]];

int yearOfBirth = [_yearTxtField.text intValue]; //Converting the value from a String into an int
NSNumber *year = [NSNumber numberWithInt:yearOfBirth]; //Converting the int into a NSNumber

//Setting each textField value to an attribute in the Entity.
[newObject setValue:_nameTxtField.text forKey:@"name"];
[newObject setValue:_streetTxtField.text forKey:@"streetName"];
[newObject setValue:_cityTxtField.text forKey:@"cityName"];
[newObject setValue:year forKey:@"yearOfBirth"];

//This log just shows what has been added to the database.
//NSLog(@"Details Save:\n\n Name: %@\n StreetName: %@\n CityName: %@\n Year of birth: %@", details.name, details.streetName, details.cityName, details.yearOfBirth);
}
4

1 に答える 1

0
- (IBAction)saveDataAction:(id)sender
{
     //Instantiating the Entity with a pointer and giving it a mission.
    NSString *details = @"Details";
    NSManagedObjectContext *context = [self managedObjectContext];
    NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:details inManagedObjectContext:context];

    int yearOfBirth = [_yearTxtField.text intValue]; //Converting the value from a String into an int
    NSNumber *year = [NSNumber numberWithInt:yearOfBirth]; //Converting the int into a NSNumber

    //Setting each textField value to an attribute in the Entity.
    [newObject setValue:_nameTxtField.text forKey:@"name"];
    [newObject setValue:_streetTxtField.text forKey:@"streetName"];
    [newObject setValue:_cityTxtField.text forKey:@"cityName"];
    [newObject setValue:year forKey:@"yearOfBirth"];

    NSError *error;
    if (![context save:&error]) {
        NSLog(@"Whoops couldn't save new object");
    }
    //This log just shows what has been added to the database.
    //NSLog(@"Details Save:\n\n Name: %@\n StreetName: %@\n CityName: %@\n Year of birth: %@", details.name, details.streetName, details.cityName, details.yearOfBirth);
}
于 2012-11-18T04:33:55.507 に答える