开发者

How to send an image to another viewcontroller

开发者 https://www.devze.com 2023-02-24 00:22 出处:网络
I have a program where I am combining two images into a single image on an UIImageView on my main ViewController.I would like to set that combined image to UIImageView on another viewController in ord

I have a program where I am combining two images into a single image on an UIImageView on my main ViewController. I would like to set that combined image to UIImageView on another viewController in order to preview it full size. I can do all of this, I just can't figure out how to send this image to the other viewcontroller's UIImageView.

How can开发者_运维问答 a set an image to a UIImageView that is on a different viewController?

thank you


Use the delegate pattern, add a method such as:

-(void)viewController: (UIViewController*)vc didReturnImage: (UIImage*)image;


First you should make an image object on that view controller where you have to show the image and then set image to that image object like:- In forthViewController do

UIImage *img;

@property(nonatomic,retain)UIImage *img;

Make sure you make property and synthesize img.

In the view Controller where you have that image:-

ForthViewController *forthView=[[[ForthViewController alloc]initWithNibName:@"ForthViewController" bundle:nil]autorelease];
forthView.img=[UIImage imageNamed:@"Default.png"];
[self.navigationController pushViewController:forthView animated:YES];

In you view controller where you have to show image do:-

UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
[imgView setImage:self.img];
[self.view addSubview:imgView];

I hope this code will work for you basically you can get the image of prevoius view controller now you can do want you want to as (combine ..) Happy Coding:)


Who owns the second view controller? Somewhere in your code, you should be able to reference that second view controller. Then, in the second view controller, just create a method called setImage:(UIImage *)image that takes a UIImage and assigns it as the image view's image.


SecondViewImage *VC = [[SecondViewImage alloc] initWithNibName:@"ViewImage" bundle:nil] ;

[VC loadView];

VC.theImage.image = chosenImage;
VC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self.navigationController pushViewController:VC animated:YES];

Note: loadView is required.

0

精彩评论

暂无评论...
验证码 换一张
取 消