用于重复使用UIAlertView的内存管理 [英] Memory management for reusing UIAlertView

查看:64
本文介绍了用于重复使用UIAlertView的内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有多个使用相同UIAlertView * alertView的View控制器类. * alertView的委托设置为集中式委托.

Lets say I have multiple View controller classes using the same UIAlertView *alertView. *alertView's delegate is set to a centralized delegate.

之所以这样做,是因为要使用.tag来基于它执行不同的操作.

I do this because would like to use the .tag to do different things based on it.

问题是每次我调用或关闭警报视图时,我该怎么做才能防止内存泄漏?

The question is every time I invoke an alert view or dismiss it, what do i have to do to prevent a memory leak?

我不应该每次都释放吗?还是这是一个非常糟糕的主意?

Should I not release every time? Or is this a very bad idea?

谢谢.

推荐答案

可以在应用程序中的任何位置显示" UIAlertView.我有一个应用程序,主UIViewController有一个计时器,每隔一个计时器就会弹出一个UIAlertView.当该计时器关闭时,即使显示的主视图是来自完全不同的UIViewController(因此是视图),也会将Alert置于最前面.

A UIAlertView may be "shown" from anywhere in your app. I have an app that the main UIViewController has a timer that every so often brings up a UIAlertView. When that timer goes off, even if my main view being shown is from a completely different UIViewController (and thus view) the Alert will come to front.

如果您真的想从您的任何UIViewControllers中主动"调出UIAlertView(让我们根据用户操作来说),那么我将做两件事之一.

If you really want to "actively" bring up the UIAlertView from any of your UIViewControllers (lets say based upon a user action), then I would do one of two things.

1)使用在那里实现的UIAlertView设置我的Application Delegate Object,并使用访问器方法来调用(显示)Alert视图,从而也从那里释放它,或者

1) setup my Application Delegate Object with the UIAlertView implemented there, with accessor methods for invoking (showing) the Alert view, and thus freeing it from there also, or

2)生成一个类似Singleton的对象,并在其中实现了AlertView !!!

2) Generate a singleton like object with the AlertView implemented there!!!

无论哪种情况,您都可以在为这些布局之一编写的dealloc例程中简单地对UIAlertView进行一次分配,并在初始化对象时仅对其进行一次分配.

In either case then you can simply dealloc your UIAlertView once within the dealloc routine you write for either of those placements, and alloc it only once when the object is initialized.

这篇关于用于重复使用UIAlertView的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆