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.
精彩评论