UIAlertView 显示两次

发布于 2024-08-24 17:29:05 字数 649 浏览 6 评论 0原文

我的警报视图出现两次,需要用户单击两次才能关闭。

    - (void) showAlert: (NSString *) message
{
 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"You chose"
             message: message
            delegate: self
            cancelButtonTitle:@"Cancel"
            otherButtonTitles:@"ok",nil];
 av.tag = SLIDER_ALERT;
 [av show];

}

然后,我在委托方法“alertView:(UIAlertView *)alertView clickedButtonAtIndex:(int)index”中释放alertview,

我怀疑问题是我已经以编程方式构建了自己的视图层次结构。我有一个视图控制器的父视图。在此之下,我有另外 2 个视图(parentView -> subview1 和 subview2)。我尝试调用 [self.view addSubview: av] 但这不起作用。 BringToFrontSubView 也不:

任何帮助将不胜感激

Peyman

My alertview appears twice and requires 2 user clicks to dismiss.

    - (void) showAlert: (NSString *) message
{
 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"You chose"
             message: message
            delegate: self
            cancelButtonTitle:@"Cancel"
            otherButtonTitles:@"ok",nil];
 av.tag = SLIDER_ALERT;
 [av show];

}

I am then releasing the alertview in the delegate method "alertView: (UIAlertView *) alertView clickedButtonAtIndex: (int) index"

I suspect the problem is that I have built my own view hierarchy programmaticaly. I have one parent view for the viewcontroller. Under that i have 2 other views (parentView -> subview1 and subview2). I've tried to call [self.view addSubview: av] but that does not work. Neither does bringToFrontSubView:

Any help would be much appreciated

Peyman

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

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

发布评论

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

评论(3

白云不回头 2024-08-31 17:29:05

警报代码很好(除了评论中提到的版本)。

[av show] 就是显示视图所需的全部内容。您不添加 UIAlertViews 作为子视图。

The Alert code is fine (other than the release, mentioned in the comments).

[av show] is all that's required to show a view. You don't add UIAlertViews as subviews.

⒈起吃苦の倖褔 2024-08-31 17:29:05

延迟0.1秒后调用 [self PerformSelector:@selector(showAlert:) withObject:nil afterDelay:0.10];

希望这能解决您的问题。

Call it after a delay of 0.1 sec [self performSelector:@selector(showAlert:) withObject:nil afterDelay:0.10];

Hope this will solve your problem.

初见终念 2024-08-31 17:29:05

使用 autorelease 后,警报视图似乎增加了两倍或三倍。对于iOS4,它需要自动释放,否则会崩溃。

With using autorelease the Alert View seems to be twice or 3 times. And for iOS4 it needs to be autoreleased otherwise it will crash.

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