为什么在显示 UIAlertView 后就释放它,而它不是阻塞方法?
我已经研究了如何使用 UIAlertView 显示模态视图几个小时,我明白显示它不会“阻止”代码(显示模态窗口并且程序继续运行 - 我们必须使用委托来捕获所选操作在此模式窗口上)。然后我研究了几个例子,发现每个例子总是在显示模式窗口后立即释放它。由于代码不会停止,视图将立即释放,这如何才能正常工作?
这是示例(Google 上还有很多其他示例):
[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message..." delegate:NULL cancelButtonTitle:@"OK" otherButtonTitles:NULL];
[alert showModal];
[alert release];
感谢您的帮助, 苹果92
I have been studying how to display a modal view with UIAlertView for a few hours and I understood that showing it does not "block" the code (the modal window is displayed and the program keeps running - we must use delegate to catch the selected actions on this modal window). Then I studied several examples and noticed that every example always release the modal window just after showing it. How can this work properly since the view will be released instantly as the code does not stop ?
Here is the example (there are many others on Google):
[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message..." delegate:NULL cancelButtonTitle:@"OK" otherButtonTitles:NULL];
[alert showModal];
[alert release];
Thanks for your help,
Apple 92
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
alloc
方法将返回一个保留计数为 1 的实例。showModal
方法可能保留
警报视图,因此它保留在屏幕上(并保留),直到点击按钮。这对我来说很有意义,因为您将其呈现为模式窗口,因此它没有负责释放它的“父级”。The
alloc
method will return you an instance that has a retain count of 1.The
showModal
method probablyretains
the alert view so it remains on screen (and retained) until a button is tapped. It makes sense to me, since you are presenting it as a modal window, so it doesn't have a "parent", that is responsible of releasing it.我不确定你从哪里得到 -showModal (通常的方法就是 -show ),但该行为将警报添加到视图层次结构中。当一个视图被添加为另一个视图的子视图时(我相信在这种情况下它是被添加到的系统级视图),它会自动保留,因此您不必这样做。
I'm not sure where you're getting -showModal from (the usual method is just -show), but that act adds the alert to the view hierarchy. When a view is added as a subview of another view (I believe in this case it's a system-level view that is being added to) it's retained automatically, so you don't have to.