I have a UIImage on my MyCartViewController. And i have a button on my BlackFacePlatesViewController. I want this button to set the image on the MyCartViewController to another image, however i can’t seem to get it to work. Here is my code for the button to set the image on the MyCartViewController:
EDIT:
I HAVE 1 BOOL VARIABLE IN VC2 AND WHEN THE BUTTON IS PRESSED IN VC1, I SET THE BOOL AND CREATE VC2. THEN IN THE VIEWWILLAPPEAR METHOD, I SET THE IMAGE ACCORDINGLY. HERE IS THE CODE: THANKS
- (IBAction)outlet1 {
MyCartViewController * imageCart = [[MyCartViewController alloc]init];
imageCart.displayImage = YES;
}
BUTTON THAT THE USER PRESSES ^
THIS IS TO SWITCH PAGES:
- (IBAction)myCart:(id)sender; {
MyCartViewController * first = [[MyCartViewController alloc]init];
first.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:first animated:YES];
[first release];
}
THIS IS THE VIEWWILLAPPEAR METHOD IN VC2:
-(void)viewWillAppear:(BOOL)animated{
if (self.displayImage == YES) {
UIImage * myImage = [UIImage imageNamed:@"Paddle_3.png"];
[outletImageView setImage:myImage];
}
}
WOULD THIS WORK? THANK YOU VERY MUCH FOR THE HELP EVERYBODY!!!
You aren’t allocating your object
cartproperly, andcart2has nothing to do withcart, apart from being a similar class. You should just make an instance variable in the header file that’s aUIImagewhich holds the image you want to use in your nextUIView, and set it when you usepresentModalViewController:Try this. In your .h file,In your .m file,
I made 2 button methods to illustrate the point of switching the image based on which button was pushed. Remember that
imageNamed:caches theUIImage, so if you have a lot, you may have to start looking into other loading methods, all of which can be found here. This should solve your problem.Edit: Try this. In your .h file,
In the .m file,
Then, when you push to the view, try:
Edit2: This is a tutorial about how to use a
UISplitViewController, which has a similar idea, where you press aUITableViewCell, and it changes an image in anotherUIView. You should look through this, and see if it can help your project.Also, try:
This is another way to move to a new
UIView, which may work.Hope that Helps!