0

所以我开始认为这将是非常简单的,但我真的无法弄清楚如何做到这一点!基本上我使用TabBar应用程序,因此每个页面由UITabBarController管理。我创建了一个UIImage,当您从照片库中选择它时显示,我希望该选择显示在不同的视图控制器中。这是我在第一个VC代码:如何在第二个ViewController中从一个ViewController显示UIImage?

- (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

ViewControllerOne *VC1; 

@property (nonatomic, retain) ViewControllerOne *VC1; 

我希望我已经很好地解释这个实例连接的两个VC的,而是要总结我想当从ViewController中弹出的光盘库中选择UIImage时,能够在ViewController 2中显示UIImage 1

回答

1

我不确定哪个VC是哪个,哪个声明在哪里,但是我认为你是什么就是说你有一张图片和一个新申报的VC初始VC。如果是这样的话,我会在你的初始VC中用你的UIImage创建一个视图,然后将它添加为你的新VC的视图或子视图。

newView = [[UIView alloc]init] ; 

    [newView addSubView:image1] ; 

然后:

[self.VC1.view addSubView:newView] ; 

或:

[self.VC1 setView:newView] ; 

很抱歉,如果我misunderstoon你的问题。也许尝试标记哪个VC更好并保持一致?

+0

很酷,我会试试看,并回复给你。感谢你的回复,我总是很难解释这些事情,除非我实际展示某人,但感谢你的建议! – Ollie177

相关问题