UIAlertView 显示两次
我的警报视图出现两次,需要用户单击两次才能关闭。
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
警报代码很好(除了评论中提到的版本)。
[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.
延迟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.
使用 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.