所以我开始认为这会很简单,但我真的不知道该怎么做!基本上我使用的是 TabBar 应用程序,因此每个页面都由UITabBarController
. 我创建了一个 UIImage,当您从照片库中选择它时会显示它,我希望该选择显示在不同的视图控制器中。这是我在第一个 VC 中的代码:
- (void)addNew:(id)sender {
NSLog(@"Clicked");
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:controller animated:YES];
[controller setDelegate:self];
[self.photoView.view removeFromSuperview];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(@"this function has started");
[self.view setAlpha:1.0f];
imageV1 = [[UIImageView alloc] initWithImage:image];
imageV1.frame = CGRectMake(10, 200, 100, 100);
image1 = image;
[imageV1 setImage:image];
[scrollView addSubview:imageV1];
[self dismissModalViewControllerAnimated:YES];
}
这样就可以在此视图中显示图像(这不是我想要的)。我希望它显示在此视图中:
- (void)viewDidLoad
{
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 500)];
imageV2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 50, 100, 100)];
imageV2.backgroundColor = [UIColor blueColor];
self.imageV2.image = VC1.imageV1.image;
[imageV2 setImage:VC1.image1];
[scrollView addSubview:imageV2];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
我通过创建 VC1 的实例链接了两个 VC
ViewControllerOne *VC1;
@property (nonatomic, retain) ViewControllerOne *VC1;
我希望我已经很好地解释了这一点,但总而言之,当从 ViewController 1 中弹出的照片库中选择 UIImage 时,我希望能够在 ViewController 2 中显示 UIImage