我创建了一个带有自定义相机选择器的应用程序,我尝试将覆盖图像从一个类传递到另一个类,下面是关于我的代码的更多信息:
使用 Storyboard:
UICollectionView
从网络加载带有图像的 .plist
,然后使用 Segue Identify
将信息传递给另一个 View 。
在我的第二个 View 中,我看到了我选择的图像、共享按钮和相机按钮,如果我点击相机按钮在单独的 .xib
中加载 mu 自定义相机 View ,我想通过我的第一个选择图像到 .xib
这里是我的代码:
3个controller的流程是:
来自 UITableView
的第一个 Controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([@"goToShare" isEqualToString:segue.identifier]) {
NSIndexPath *index = [self.tableView indexPathForCell:sender];
[[segue destinationViewController] setImgSelected:(self.loadImage)[index.row]];
}
}
这里将我的图片设置为 NSMutableDictionary *imgSelected;
在我的第二个 Controller 中,我将信息输入:
- (void)viewDidLoad {
NSString *url = (self.imgSelected)[@"image"];
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
imageViewPick.image = [[UIImage alloc] initWithData:data];
[super viewDidLoad];
}
现在我想从第二个 Controller imageViewPick.image
将第三个 Controller 中的相同图像传递到我的 imageOverlay.image
当点击相机按钮并垂直加载封面时,我的 .xib
:
- (IBAction)getPhoto:(id) sender {
CustomCameraViewController *camController = [[CustomCameraView alloc] initWithNibName:@"CustomCameraView" bundle:nil];
camController.delegate = self;
[self presentViewController:camController animated:YES completion:^{
}];
}
我尝试通过以下方式获取 imageViewPick.image
:
MyFirstView *imgDelegate= (MyFirstView *)[[UIApplication sharedApplication] delegate];
self.imageOverLay.image = imgDelegate.imageViewPick.image;
但无法正常工作并且应用程序崩溃。
知道如何将信息从 firstClass.m
传递到 secondClass.m
吗?
最佳答案
initWithNibName
方法返回UIViewController
,让我们调用MySecondViewController
的实例。将 UIImage
属性添加到 MySecondViewController
。然后,初始化 MySecondViewController
实例后,将 UIImage
属性设置为所需的图像。例如:
在MySecondViewController.h中:
...
@property (nonatomic, weak)UIImage *overlayImage;
...
在MyFirstView.m中:
...
MySecondViewController *secondViewController = [MySecondViewController initWthNibName:<insert name of xib> bundle:<probably nil>];
secondViewController.overlayImage = self.imageOverlay.image;
...
然后,您可以使用 self.overlayImage
访问 MySecondViewController
中的叠加图像
关于ios - ImageView 将信息从类传递到其他类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24695797/