Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone App - dismissing modal view controller doesn't dealloc it

I have a UIViewController (call it NumberTwo) which I presented as a modal view controller from another UIViewController (call it NumberOne). NumberTwo contains a touchesBegan method which listens for touches, and it also has an accelerometer method which listens for device orientation changes in the x, y, or z direction. NumberTwo has a button called "Done" which, when tapped, dismisses itself as a modal view controller:

[self dismissModalViewControllerAnimated:NO];

But it seems as though it's still listening for touches, and it's still listening for accelerations. How can I completely free up NumberTwo when I dismiss it? I tried adding a release call as follows:

[self dismissModalViewControllerAnimated:NO];
[self release];

but that caused a EXEC_BAD_ACCESS.

like image 401
StanLe Avatar asked Jul 11 '11 03:07

StanLe


1 Answers

Did you release the controller after you presented it? E.g. in your method in NumberOneController that presents it, do you have something like:

NumberTwoController * controller = [NumberTwoController alloc] init];
// do stuff to config controller
[self presentModalViewController: controller];
[controller release];

Unless you want to hang on to NumberTwoController for re-use, this would be the usual pattern. The presentModalViewController method ensures that the controller is retained while it's in use. It should then get tidied up when, within NumberTwoController, you call [self dismissModalViewControllerAnimated: NO].

like image 149
Obliquely Avatar answered Oct 12 '22 21:10

Obliquely