Reputation: 3356
I currently have code to open a UIViewController, in this case you have opened it before so it will not totally load from scratch. So the old data will still be there when you return. I am not trying to save the data for the next time you go in the app. Only in that session. I am trying to adapt this code to the iPad for a UIPopOver. I have tried but am not able to do it.
//without popover
- (IBAction) addPerson:(id) sender{
if (addPersonController == nil) {
addPersonController = [[addPersonViewController alloc] initWithNibName:@"addPersonViewController" bundle:nil];
}
addPersonController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:addPersonController animated:YES];
[addPersonController retain];
}
//popover
- (IBAction) addPerson:(id) sender{
// create your view controller if it doesn't exist yet
if (dateViewPopOverController == nil){
addPersonViewController1 = [[addPersonViewControllerPopover_iPad alloc] init];
}
pop = [[UIPopoverController alloc] initWithContentViewController:addPersonViewController1];
// rest of your method...
addPersonViewController1.delegate = self;
pop.popoverContentSize = CGSizeMake(320, 480);
CGRect rect = CGRectMake(790, 35, 175, 300);
[pop presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
Upvotes: 2
Views: 1307
Reputation: 895
You can keep the dateViewPopOverController as an instance variable in the view controller you are presenting the popover from. That way, when a popover is dismissed, your view controller still holds on to the dateViewPopOverController that was displayed.
in your .h file:
@interface YourViewControllerName : UIViewController {
dateViewPopOverViewController_iPad *dateViewPopOverViewController;
// other ivars...
}
@property (nonatomic, retain) dateViewPopOverViewController_iPad *dateViewPopOverViewController;
// other @properties...
in your .m file:
synthesize:
@synthesize dateViewPopoverController;
your method:
- (IBAction) selectStartDate:(id) sender {
NSLog(@"Select start date");
// create your view controller if it doesn't exist yet
if (dateViewPopOverController == nil)
dateViewPopOverViewController =
[[dateViewPopOverViewController_iPad alloc] init];
popover2 = [[UIPopoverController alloc]
initWithContentViewController:dateViewPopOverViewController];
// rest of your method... *but do not release the dateViewPopOverViewController here*
}
release the controller in dealloc:
- (void) dealloc {
[dateViewPopOverViewController release];
// rest of dealloc...
}
Upvotes: 1
Reputation: 60508
It looks like you just need an instance variable to hold your dateViewPopOverViewController_iPad
instance. Then use the same "if it's nil, create an instance" logic that you had for the DateViewController
in the non-popover code.
Upvotes: 1