【发布时间】:2012-11-13 02:40:01
【问题描述】:
如何将MainViewController中uiimagepickercontroller中选中的uiimage传递给SecondViewController?它确实推送到了 SecondViewController,但是 uiimage 是空的。
我在网上搜索过,尝试了解决方案,但仍然无法正常工作。
photoImage 是我在 SecondViewController 中声明的uiimageview。
- (void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[secondVC.photoImage setImage:[info objectForKey:@"UIImagePickerControllerEditedImage"]];
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
}
【问题讨论】:
-
[secondVC release]不是问题所在,因为您在将其推送到导航控制器的堆栈后立即释放它? -
我去掉
[secondVC release];还是一样,实在想不通 -
photoImage的属性声明是什么样的?如果您在调用setImage:之前输入NSLog(@"Image: %@", [info objectForKey:@"UIImagePickerControllerEditedImage"]);,您会得到什么? -
@psycho 情况并非如此,通过将 viewController 推到导航堆栈上,navigationController 会保留它,因此它是安全的,并且需要
release -
@zeropt7 执行@phillip Mills 提到的检查,并注意您应该使用常量
UIImagePickerControllerEditedImage,而不是使用字符串@"UIImagePickerControllerEditedImage"。它们具有相同的值,但 Apple 可能会决定在以后更改此值。使用常量还将确保编译器检查常量的拼写以保存字符串中的拼写错误
标签: objective-c cocoa-touch uiviewcontroller uiimage uiimagepickercontroller