UIImageView に問題があります。私のプロジェクトでは、2 つUIImageView
の を (mainview
背景色の保存とdrawimage
描画に) 使用しました。1 つはもう 1 つのサブビューです。
[self.view addSubview:mainview];
[self.mainview addSubview:drawImage];
問題は、Core Data にオブジェクトを保存しようとすると、常に 1 つの画像しか保存されないことです。これは私のコードです:
if(checkedcore==YES)
{
NSData *imageData = UIImageJPEGRepresentation(mainview.image,1.0);
NSManagedObject *imagetblObj= [NSEntityDescription insertNewObjectForEntityForName:@"Imagedata" inManagedObjectContext:context];
//[imagetblObj setValue:<#(id)#> forKey:<#(NSString *)#>]
//[imagetblObj setValue:self.imageData forKey:@"imageData"];
[imagetblObj setValue:imageData forKey:@"imageData"];
[imagetblObj setValue:self.textfield.text forKey:@"date"];
[imagetblObj setValue:@"table" forKey:@"tabletext"];
[context deleteObject:imagemanaged];
[context insertObject:imagetblObj];
NSError *err;
if (![context save:&err])
{
NSLog(@"Couldn't save history item into coredata");
}
else
{
NSLog(@"data saved");
}
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:@"" message:@"Image Updated" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
NSLog(@"data saved");
NSLog(@"save clicked");
/// [self getcoredata];
// TextPlacedViewController *viewcontroller=[[TextPlacedViewController alloc]initWithNibName:@"TextPlacedViewController" bundle:nil];
///viewcontroller.tabledata=self.array;
////viewcontroller.myimage=drawImage.image;
///[self.view addSubview:viewcontroller.view];
// [self.navigationController popViewControllerAnimated:YES];
}
}
else
{
mainview.image=drawImage.image;
NSData *imageData = UIImageJPEGRepresentation(mainview.image, 1.0);
if(![imageData isKindOfClass:[NSNull class]]||imageData==nil)
{
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *imagetblObj= [NSEntityDescription insertNewObjectForEntityForName:@"Imagedata" inManagedObjectContext:context];
[imagetblObj setValue:imageData forKey:@"imageData"];
[imagetblObj setValue:self.textfield.text forKey:@"date"];
[imagetblObj setValue:@"table" forKey:@"tabletext"];
NSError *err;
if (![context save:&err])
{
NSLog(@"Couldn't save history item into coredata");
}
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:@"" message:@"Data Saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
NSLog(@"data saved");
NSLog(@"save clicked");
/// [self getcoredata];
saveimageviewcontroller *viewcontroller=[[saveimageviewcontroller alloc]initWithNibName:@"saveimageviewcontroller" bundle:nil];
///viewcontroller.tabledata=self.array;
////viewcontroller.myimage=drawImage.image;
///[self.view addSubview:viewcontroller.view];
[self.navigationController pushViewController:viewcontroller animated:YES];