iphone - 将图像从一个 View 设置为另一个 xcode 4.4

标签 iphone objective-c ios xcode uiimageview

我有 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;

这会将图像分配给 UITabBarControllerAdjustViewControllerviewImage 属性,假设您使用了正确的索引。

或者,如果您想将内容压缩到尽可能少的行中:

((AdjustViewController *)[[self.tabBarController viewControllers] objectAtIndex:0]).viewImage.image = image;

关于iphone - 将图像从一个 View 设置为另一个 xcode 4.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184486/

相关文章:

ios - 使用核心数据在 NSDate 属性中仅按年份过滤 TableView Controller

iphone - 自定义 Arial-Narrow.ttf 字体集成

objective-c - 如何使用 block 完成处理程序实现类方法

ios - ionic 电容器WKWebView视口(viewport)高度不一致

iphone - 固定位置在 iPhone 中不起作用

iphone - 为什么 UITextField 中的文本是从底部剪切的?

objective-c - 更改属性值时使用 Core Data 时出现 EXC_BAD_ACCESS 错误

iphone - 袖珍 API : how to modify data using callAPIMethod?

iPhone,在现有基于 View 的项目中使用表格 View

ios - 从 Swift 函数中的异步调用返回数据