Ios 在应用程序的详细视图中存储图片,该应用程序的主界面是表视图控制器
因此,我正在制作一个非常基本的iOS应用程序,在这个应用程序中,我希望能够从照片库中选择一张图片,并将其保存在VC中,当您从table view controller中选择一个单元格时,它会显示出来 存储我的图片的代码是:Ios 在应用程序的详细视图中存储图片,该应用程序的主界面是表视图控制器,ios,objective-c,image,Ios,Objective C,Image,因此,我正在制作一个非常基本的iOS应用程序,在这个应用程序中,我希望能够从照片库中选择一张图片,并将其保存在VC中,当您从table view controller中选择一个单元格时,它会显示出来 存储我的图片的代码是: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismiss
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissModalViewControllerAnimated:YES];
UIImage *fullImage = (UIImage *) [info
objectForKey:UIImagePickerControllerOriginalImage];
[Data setCurrentKey:[info objectForKey:UIImagePickerControllerOriginalImage]];
self.image = fullImage;
[self makeObjects];
NSString *key = [[NSDate date] description];
[Data setNote:kDefaultText forKey:key];
[Data setCurrentKey:key];
[_objects insertObject:key atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self performSegueWithIdentifier:kDetailView sender:self];
}
下面是我选择特定单元格后检索VC的代码:
- (void)setImageObject:(UIImage *)image
{
self.tView.frame = CGRectMake(50, 200, self.view.bounds.size.width,
self.view.bounds.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 100, self.view.bounds.size.width, 200);
[self.view addSubview:imageView];
}
- (void)configureView
{
// Update the user interface for the detail item.
NSString *currentNote = [[Data getAllNotes] objectForKey:[Data getCurrentKey]];
UIImage *currentImage = [[Data getAllNotes]
objectForKey:UIImagePickerControllerOriginalImage];
if(![currentNote isEqualToString:kDefaultText]) {
self.tView.text = currentNote;
self.imageView.image = currentImage;
}
else {
self.tView.text = @"";
}
}
出于某种原因,即使每个注释中的文本正在保存,图像也不会保存。我做错什么了吗 事实上,我不确定您在didFinishPickingMediaWithInfo中的代码是否会在[self dismissModalViewControllerAnimated:YES];之后执行;。无论如何,因为您正在调用[self-PerformsgueWithIdentifier:kDetailView sender:self];我猜你在用故事板。在本例中,我建议使用-voidPrepareforsgue:UIStoryboardSegue*segue sender:idsender;您可以在其中使用任何数据设置新的视图控制器。我们可能会看到您的数据类,尤其是setCurrentKey:实现。在一种情况下,使用UIImage实例调用此方法;在另一个字符串中。因此,我不确定您的数据模型是如何构建的。看起来有点不正统。