gpt4 book ai didi

iphone - 分配的对象的潜在泄漏 - UIViewController

转载 作者:行者123 更新时间:2023-12-03 20:09:29 25 4
gpt4 key购买 nike

我的应用程序是基于 View 的应用程序。我有 3 个 View Controller 。 (主要、次要、细节)每个 View Controller 都有一个 UIView。在 MainViewcontroller 中,有一个启动 subview 的按钮。方法如下。

-(IBAction) LaunchSubView: (id)sender {

subViewcontroller *viewController = [[subViewcontroller alloc] init];

UIView *currentView = self.view;
[UIView transitionFromView:currentView
toView:viewController.view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){}];

}

当我尝试构建和分析时,我收到了此警告。第 54 行分配并存储到“viewController”中的对象存在潜在泄漏我在transitionFromView方法和subViewcontroller *viewController = [[[subViewcontroller alloc] init] autorelease]之后尝试了[viewController release];这两种方式都会导致应用程序崩溃。知道我该怎么办吗?预先感谢您的任何帮助。 =)

最佳答案

transitionFromView:toView:duration:options:completion: 不是正确的使用方法。您可能应该使用 presentModalViewController:animated:

如果您阅读了 transitionFromView:toView:duration:options:completion: 的文档,它会解释:

This method modifies the views in their view hierarchy only. It does not modify your application’s view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change."

关于iphone - 分配的对象的潜在泄漏 - UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4653869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com