我有 2 个 View ,它们是 UITabBarController 的一部分。我为每个 View 声明了一个不同的类。
PictureViewController
方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[imagePicker dismissModalViewControllerAnimated:YES];
[imageField setImage:image];
}
另一个 View :AdjustViewController
和另一个 UIImage:
@property (weak, nonatomic) IBOutlet UIImageView *viewImage;
我想在上面的方法 - didFinishPickingImage 中将 AdjustViewController
中的 viewImage 的值设置为所选图像。
我该怎么做?
最佳答案
由于这两个都在 tabBarController 中,您可以使用 tabBarController
获取对另一个 View Controller 的引用并从那里访问其属性。
像这样:
NSArray *theViewControllers = [self.tabBarController viewControllers];
//On this line, you will need to use the Index of the AdjustViewController (0 is on the left and then they go in order from left to right.)
AdjustViewController *adjViewController = (AdjustViewController *)[theViewControllers objectAtIndex:0];
adjViewController.viewImage.image = image;
这会将图像分配给 UITabBarController
上 AdjustViewController
的 viewImage
属性,假设您使用了正确的索引。
或者,如果您想将内容压缩到尽可能少的行中:
((AdjustViewController *)[[self.tabBarController viewControllers] objectAtIndex:0]).viewImage.image = image;
关于iphone - 将图像从一个 View 设置为另一个 xcode 4.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184486/