I have an app and on the first page is a button that the user can set an image which is on the second page.
To switch pages, the code im using is:
- (IBAction)myCart:(id)sender; {
MyCartViewController * cart2 = [[MyCartViewController alloc]init];
cart2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:cart2 animated:YES];
[cart2 release];
}
And i also have another method this allows the user to press a button and set an image.
- (IBAction)outlet1 {
cart.displayImage = YES;
}
cart is a ivar created in the .h file so i can use it through out the whole file. My problem is that i need to be able to use cart (not cart2) in the myCart method. How can i do this? Because if i try to swtich the cart2’s with just cart and i delete the line:
MyCartViewController * cart2 = [[MyCartViewController alloc]init];
the app crashes when i try to switch pages. How can i use the same variable for both methods? Thanks everybody!
cart2is local reference variable and can not persist beyond the methodmyCart. Instead declare it as a part of interface variable and initialize it in theinitmethod. Don’t forget to release it finally at the end where you are releasing all interface member variables ( indealloc).