开发者

Passsing an image from one view to other

I have two view controllers in my app and both views have table view in them and both table views have certain buttons in them representing some images.when i select a开发者_开发知识库 button from table view in view 1 then image corresponding to that button is to set on the button1 in table view in view 2.How can i do it.How can i pass image from a view to other .Please respond.

Thanks, Christy


This is what named properties are useful for.

Let's say view 2 has this (among other things):

@interface ViewTwo :: UIViewController
{
    UIImage *viewTwoImage;
}

@property (nonatomic, retain) UIImage *viewTwo;

@end;

And then

@implementation ViewTwo

@synthesize viewTwoImage;

-(void)dealloc
{
    [viewTwoImage release];
    [super dealloc];
}

Then elsewhere (ie wherever you're creating your instance of this view controller) you can say:

ViewTwo *myViewTwo = [[ViewTwo alloc] initWithNibName:@"viewTwo" bundle:nil];
myViewTwo.viewTwoImage = myUIImageFromThisController;

And you've now initialized your view two instance with a pointer to that same UIImage in its .viewTwoImage property. ViewTwo can then use that image for whatever it's useful for, in its -(void)viewDidLoad method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜