Unwind segue does not release my view controllers

巧了我就是萌 提交于 2019-12-10 21:13:37

问题


I have something like this:

My rootViewController is a navigationBar - let this be A. The rest are normal UIViewControllers, and are programmatically segue via push (through a button IBAction method).

However going from D -> A, I use unwind segue (also via performSegueWithIdentifier:sender:).

The issue here is that when the segue is performed, B, C and D are not deallocatedat all. Not only is this causing a memory leak issue but my timers are still running. I'm not sure why this is the case. I thought unwind segues are suppose to handle all these for you? Any idea why?


回答1:


The issue is with the NSTimer.

NSTimer retain their target. So if a view controller starts a timer with target:self, it will not be deallocated as long as the timer is running.

You can get more information here




回答2:


-(void)viewWillDisappear:(BOOL)animated{
    [timer invalidate];
    timer = nil;
}

Hope this will help you...for timer invalidate on other controller



来源:https://stackoverflow.com/questions/27481736/unwind-segue-does-not-release-my-view-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!