Ric*_*ald 41 iphone objective-c uialertview ios
我有一个方法发布HTTP数据,并在出现错误时显示UIAlertView.如果我有多个HTTP帖子,我将为每个错误显示多个UIAlertView.
我只想在没有显示其他UIAlertView的情况下显示UIAlertView.我怎么能确定这个?
Koe*_*oen 60
为什么不检查由UIAlertView类维护的visible属性?
if (_alert) //alert is a retained property
{
self.alert = [[[UIAlertView alloc] initWithTitle:@"Your Title"
message:@"Your message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK"] autorelease];
}
if (!_alert.visible)
{
[_alert show];
}
Run Code Online (Sandbox Code Playgroud)
小智 53
在调用UIAlertView上调用show方法之前设置ivar的对象上.
...
if (!self.alertShowing) {
theAlert = [[UIAlertView alloc] initWithTitle:title message:details delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
self.alertShowing = YES;
[theAlert show];
}
...
Run Code Online (Sandbox Code Playgroud)
然后在警报管理的委托方法中将标志ivar设置为no:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
...
self.alertShowing = NO;
}
Run Code Online (Sandbox Code Playgroud)
如果您希望按顺序显示警报,我会发布通知以将每条消息添加到队列中,然后仅在警报解除后从队列中取消消息.
ken*_*ytm 26
如果您可以控制其他警报视图,请检查visible
每个警报视图的属性.
在iOS 6或之前,当出现警报时,它将被移动到_UIAlertOverlayWindow.因此,一个非常脆弱的方法是迭代所有窗口并检查是否有任何UIAlertView子视图.
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]])
return YES;
}
return NO;
Run Code Online (Sandbox Code Playgroud)
这是没有记录的,因为它取决于内部视图层次结构,虽然Apple不能抱怨这一点.更可靠但更无证的方法是检查是否[_UIAlertManager visibleAlert]
为零.
这些方法无法检查是否显示了SpringBoard的UIAlertView.
小智 9
- (BOOL)checkAlertExist {
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0) {
for (id cc in subviews) {
if ([cc isKindOfClass:[UIAlertView class]]) {
return YES;
}
}
}
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
48317 次 |
最近记录: |