[英]`UIAlertView` appears multiple times
我在didConnect
方法的蓝牙中显示警报视图。 由于某种原因,它会触发四次。 我正在尝试将其粘贴,但效果不是很好。 基本上,我将警报视图放在自己的方法中,然后在didConnect
调用该方法。 那是它触发四次的时候。 我正在尝试将其设置为仅触发一次。 我试图做的是将警报视图方法设置为返回TRUE
值。 然后我这样做:
if ([successfulConnection self] == FALSE) {
[self successfullConnection];
}
这在第一次时效果很好,但是随后在其余时间将该方法设置为TRUE
。 我有一种感觉,如果我在if语句的末尾将其设置为FALSE
,那么它将触发四次,并且我将回到开始的位置。 有谁知道如何更改以上代码以使其在尝试触发四次时仅触发一次?
还尝试在我的didConnect
上面的代码替换上面的代码,但是根本没有触发:
[successfulConnection self];
if (successfulConnection.visible == YES) {
[successfulConnection dismissWithClickedButtonIndex:0 animated:YES];
}
如果您从didConnect方法调用成功连接,我认为这应该可以工作(myAlert是警报视图的属性名称):
-(void)successfulConnection {
if (! self.myAlert) {
self.myAlert = [[UIAlertView alloc]initWithTitle:@"ttile" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles: nil];
[self.myAlert show];
}
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
self.myAlert = nil;
//do whatever with the result
}
最简单的操作是只具有一个布尔值,当显示UIAlertView时将其设置为true,然后在取消UIAlertView时将其设置为false。 然后,每当要显示UIAlertView时,首先检查它是否已经显示。
要知道, alertView
是currently
visible
or not
。
Usage
:仅在必要时显示alertView。
-(UIAlertView *)getLastAlertView
{
Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *topMostAlert = [UIAlertManager performSelector:@selector(topMostAlert)];
return topMostAlert;
}
Dissmiss
您不知道的any
alertView
present
。
Usage
:关闭所有alertView,然后显示一个新的
-(void)dissmissLastAlert
{
Class UIAlertManager = objc_getClass("_UIAlertManager");
UIAlertView *topMostAlert = [UIAlertManager performSelector:@selector(topMostAlert)];
if (topMostAlert) {
[topMostAlert dismissWithClickedButtonIndex:0 animated:YES];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.