Hello i have a very simple question, I have initialized some variables and started the motion manager updates on the “viewDidLoad” method, but after i finish using it I am closing the window and returning to the previews one. My question is whether the method is being called everytime i open that window trough a segue in the storyboard. (Since the description says it does it when it loads it to memory not to the screen)
I am closing the window by telling that window that the previous one is its delegate like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Drawing"])
{
DrawingViewController *temp = segue.destinationViewController;
temp.delegate = self;
}
}
and then when the user clicks the closing button in the new window it tells the delegate (the previous screen) to close him:
- (IBAction)cancel:(id)sender
{
[self.delegate DrawingViewControllerDidCancel:self];
}
This is the closing method:
- (void)DrawingViewControllerDidCancel: (DrawingViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Oh and if someone would be so kind to tell me why is it that by calling self i am closing the other window, (Because i think self refers to the delegate not to the one that i want to close).
Thank you very much!
Put some log statements in the viewDidLoad method, this will be easy enough to find out for yourself. You can’t expect a view controller that has been dismissed to be hanging around in memory – it could get unloaded at any time due to a low memory situation. You’ve even called it
temp😉dismissModalViewControlleris passed along the view controller chain, you can call it on the modal controller itself or the presenting controller, it has the same effect. The currently presented modal view controller is dismissed.From the documentation: