[英]transitionFromView:toView:duration:options:completion view memory management?
It doesn't seem like 好像不是
transitionFromView:toView:duration:options:completion:
Handles memory like it indicates in the Apple docs. 按照Apple文档中的指示处理内存。 It is stated that the fromView
is removed from the superview (implying a release
) and the toView
is added to the superview (implying a retain
). 声明fromView
已从fromView
视图中删除(这意味着一个release
),而toView
被添加到了toView
视图(这意味着一个retain
)。 Is this correct? 这个对吗?
When I transition a view, later in my app when the view is actually presented I will get a BAD_ACCESS
as the view was deallocated. 当我转换视图时,稍后在我的应用中,当该视图实际呈现时,随着该视图的重新分配,我将得到一个BAD_ACCESS
。
Any ideas? 有任何想法吗? Thanks! 谢谢!
UPDATE: 更新:
Here is the code where the problem exists: 这是存在问题的代码:
UIViewController *container = [[UIViewController alloc] init];
container.view.bounds = [UIScreen mainScreen].bounds;
[container.view setBackgroundColor:[UIColor blackColor]];
/* Deallocated in the finish callback */
tutorialViewController = [[TutorialViewController alloc]
initWithNibName:@"TutorialViewController"
bundle:nil];
tutorialViewController.tutorialDelegate = self;
[tutorialViewController loadTutorialData:data];
UINavigationController *nc = [[UINavigationController alloc]
initWithRootViewController:tutorialViewController];
nc.navigationBar.barStyle = UIBarStyleBlackOpaque;
[UIView transitionFromView:[[window subviews] objectAtIndex:0]
toView:container.view
duration:kAnimationDuration
options:UIViewAnimationOptionTransitionCurlUp
completion:nil];
[container presentModalViewController:nc animated:NO];
[container release];
[nc release];
If I do a [tutorialViewController release]
at the bottom of this method, I will get the BAD_ACCESS
. 如果在此方法的底部执行[tutorialViewController release]
,则将获得BAD_ACCESS
。 So it seems like the UINavigationController does not retain the root view controller. 因此,似乎UINavigationController 没有保留根视图控制器。
PS The tutorialViewController was not a member variable previously, but I have now fixed this problem by simply releasing it after the view has been dismissed. PS PSViewViewController以前不是成员变量,但是我现在通过在取消视图后简单地释放它来解决此问题。
You should check and confirm that you are not releasing the view yourself, hereby over-releasing. 您应该检查并确认自己没有释放视图,从而过度释放。 Or perhaps check the dealloc method for the view class which is being released to see if you're over-releasing anything in it. 或者也许检查正在释放的视图类的dealloc方法,以查看是否过度释放了其中的任何内容。
The answer, after much testing, is simply that UINavigationViewController
does not retain the view with initWithRootViewController
. 经过大量测试,答案很简单,就是UINavigationViewController
不会使用initWithRootViewController
保留视图。 The Apple docs aren't clear on this. 苹果文档尚不清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.