为什么在显示 UIAlertView 后就释放它,而它不是阻塞方法?

发布于 2024-09-19 00:09:17 字数 411 浏览 2 评论 0原文

我已经研究了如何使用 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 技术交流群。

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

发布评论

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

评论(2

生来就爱笑 2024-09-26 00:09:21

alloc 方法将返回一个保留计数为 1 的实例。
showModal 方法可能保留警报视图,因此它保留在屏幕上(并保留),直到点击按钮。这对我来说很有意义,因为您将其呈现为模式窗口,因此它没有负责释放它的“父级”。

The alloc method will return you an instance that has a retain count of 1.
The showModal method probably retains 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.

望笑 2024-09-26 00:09:20

我不确定你从哪里得到 -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.

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