调用presentModalViewController后卸载View?

发布于 2024-11-01 15:05:23 字数 419 浏览 3 评论 0原文

我有一些视图控制器,我使用以下方法调用它:

myViewController *myView = [[myViewController alloc] initWithNibName:nil bundle:nil];
    myView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:myView animated:YES];
    [myView release];

如果我使用该应用程序几次,我会收到内存警告,并且应用程序会冻结几秒钟!我认为原因是我切换了视图但没有释放旧的视图!!?!!!?!! (我将插座设置为零并释放它们)

切换到新视图后如何卸载旧视图?

提前致谢

I have some view controller which I call with the following method:

myViewController *myView = [[myViewController alloc] initWithNibName:nil bundle:nil];
    myView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:myView animated:YES];
    [myView release];

if I use the app a few times I get a memory warning and the app freezes for a few seconds! I think the reason is that i switch the view but not discharged the old one !!?!!?!!
(i set my outlets to nil and release them)

how can I unload the old view after switching to the new one?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弃爱 2024-11-08 15:05:23

切换视图时,请务必在 myViewController 上调用dismissModalViewController:(BOOL)animated。

When switching the view be sure to call dismissModalViewController:(BOOL)animated on myViewController.

长伴 2024-11-08 15:05:23

在启动 modalViewController 的类中,您可以为保留的模态视图控制器创建一个属性。然后你可以写这样的东西。

//This would be in an action or something...
if (self.myViewControllerProperty == nil) {
    self.myViewControllerProperty = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];
}

[self presentModalViewController:self.myViewControllerProperty animated:YES];

然后而不是设置

myView.modalTransitionStyle =
UIModalTransitionStyleCoverVertical;

将该代码移至 modalViewController 并写入 self.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 我认为这看起来更干净,保持每个视图控制器的配置分开,不要混淆。

正如maclema所说,调用dissmissModalViewController,但你可能正在这样做......

In the class that launch the modalViewController you could make a property for the modal viewcontroller which you retain. Then you could write something like this.

//This would be in an action or something...
if (self.myViewControllerProperty == nil) {
    self.myViewControllerProperty = [[[MyViewController alloc] initWithNibName:nil bundle:nil] autorelease];
}

[self presentModalViewController:self.myViewControllerProperty animated:YES];

Then instead of setting the

myView.modalTransitionStyle =
UIModalTransitionStyleCoverVertical;

Move that code to the modalViewController and write self.modalTransitionStyle = UIModalTransitionStyleCoverVertical; I think that looks cleaner, keep the configuration of each viewcontroller separted don't mix it up.

And as the maclema said, call dissmissModalViewController, but you probably are doing that...

浪漫之都 2024-11-08 15:05:23

可能会出现很多问题,但您不需要(也不能)卸载旧视图。确保在所有视图控制器的 viewDidUnload 中释放对象并将出口设置为 nil。当发生内存警告时,viewDidUnload 将被调用,因此如果您没有正确处理它,就会出现泄漏并可能崩溃。除此之外,很难知道您的应用程序还做了什么导致崩溃的事情。

Could be any number of problems but you don't need to (and can't) unload the old view. Make sure you are releasing objects and setting outlets to nil in viewDidUnload of all of your view controllers. viewDidUnload will be called when a memory warning occurs so if you don't handle it correctly you'll have leaks and can crash. Other than that, hard to know what else your app is doing that is contributing to the crash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文