Reputation: 2563
When I leave my View Contoller, I use:
[self dismissViewControllerAnimated:YES completion:nil];
Does this 'destroy' the View Controller and it's state?
I want to leave the View Controller in the state it's in, scrollViews with buttons on etc and then return to it when I press the parent's button that handles entry to the VC. I use code in the parent like this:
- (void)handleDoubleTap:(UITapGestureRecognizer *)doubleTap {
realTaggingScreen = [[TaggingScreenViewController alloc]init];
realTaggingScreen.topLeftCornerImage = self.imageToPresent;
realTaggingScreen.salescallDate = self.salescallDate;
realTaggingScreen.shopName = self.shopName;
realTaggingScreen.refToThumbnailsVC = self.presentingThumbnailViewController;
realTaggingScreen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:realTaggingScreen animated:YES];
}
I know this is OBVIOUSLY wrong due to alloc init.
I tried to give my Tagging Screen a reference to the parent and a BOOL called iExist as well as giving my parent a reference to the Tagging Screen, then if the BOOL is true, open the reference to the child, otherwise alloc init etc but this didn't work. I can't help thinking this isn't the right way to go about it....
I will also want to save certain objects in the NSDocuments Directory and load them etc between app runs but I know how to do that. For now I'd settle for a way to make the VC state temporarily persist
Any help would be good.
Upvotes: 0
Views: 629
Reputation: 1590
if you are using ARC, the view controller will be released if no pointers are pointing to it anymore.
I would reccommend creating a strong pointer to an instance of realTaggingScreen
something like
@property(nonatomic, strong)TaggingScreenViewController *realTaggingScreen;
if i get what you are trying to do, you dont need a BOOL iExist. you can use
self.realTaggingScreen = nil;
if you don't need it to persist anymore then you can check if you need to allocate a new instance using
if(self.realTaggingScreen) {
//initialize...
}
Upvotes: 2
Reputation: 14068
When you dismiss a view controller then it is released.
Unless of course, and this provides you with an answer, you keep some strong reference to it somewhere.
AppDelegate may be a good location for keeping a reference or the calling view controller. Depends on how you want to deal with it. If you keep a strong reference for later use, then bare in mind that you just present it next time but do not create (alloc,init) it again.
If you keep a reference and re-use that then make sure that you display it only once at a time. Eg. You shoud not have your application (delegate) present controller A which presents controller B which persents C which presents B again. If you want to do that then you should create a second instance of B within C and present this B2.
(You may display a view for a second time somewhere else which will make it moving from the old place to the new, but you should not do that within a view controller in your view hierarchy - regardless whether you present or push them.)
Upvotes: 2