IPhone App - rejecting a modal view controller does not cancel it

I have a UIViewController (name it NumberTwo) which I introduced as a modal view controller from another UIViewController (name it NumberOne). NumberTwo contains a touchhesBegan method that listens for touches, and also has an accelerometer method that listens for device orientation changes in the x, y, or z direction. NumberTwo has a "Done" button, which when pressed, is rejected as a modal view controller:

[self dismissModalViewControllerAnimated:NO]; 

But it looks like he is still listening to touch, and he is still listening to acceleration. How can I completely free NumberTwo when I fire him? I tried adding a call to release as follows:

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

but it caused EXEC_BAD_ACCESS.

+6
source share
3 answers

Did you release the controller after it was introduced? For instance. in your method in NumberOneController that represents it, do you have something like:

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

If you do not want to embed NumberTwoController for reuse, this will be a regular template. The presentModalViewController method preserves the controller during its use. Then it should be removed when you call [self dismissModalViewControllerAnimated: NO] in NumberTwoController .

+3
source

I had a very similar problem that tormented me all day. It turned out that my view controller class was not released when I rejected it because the view controller had an active NSTimer that was not invalidated (stopped). I was able to kill the timer in viewDidDisappear.

+3
source

Make sure you release everything you use when you're done with it; The dealloc method is called only when the UIViewController and all its properties / objects are no longer used. Never use [self release]; , you need to free it from the view controller that created it after you are done with it.

+1
source

Source: https://habr.com/ru/post/892457/


All Articles