通过UIAlertView显示UIActionSheet

对于特定的服务器通知,我应该显示一个UIActionSheet。 但这里的问题是,当这个事件来了,同时,如果有任何UIAlertView已经显示在任何视图控制器上,它使UIActionSheet禁用(按下确定的警报视图,我不能够select视图控制器上的任何东西,视图被禁用,因为的UIActionSheet)。 任何人都面临这样的问题,任何想法如何解决?

我已经试图在显示操作表之前closures警报视图,但是我需要closures哪个警报视图,因为在许多控制器中有许多警报视图。 所有这些控制器都是本地的。 如何解决这个问题呢。

注意:同样的问题不会出现在iPod上,因为在回复UIActionSheet之前,不会允许点击确定。

以全局警报视图命名为activeAlertView。 现在,当您显示警报视图时,请检查该警报视图,然后显示并分配。 喜欢

在.h中声明一个属性并合成它

@property (nonatomic, retain) UIAlertView *activeAlertView; 

然后尝试显示警报时使用下面的代码。

 if(self.activeAlertView){ [self.activeAlertView dismissWithClickedButtonIndex:0 animated:YES]; } UIAlertView *localAlert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Your message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil ]; [localAlert show]; self.activeAlertView = localAlert; [localAlert release]; 

这样你的activeAlertview将保持当前的aler视图的引用,并在显示actionSheetclosures警报视图之前。

对于识别哪个alert-view您必须设置标记alert-view

例如: –

 alertviewName.tag=1; 

然后你可以检查是否有警报视图打开在特定的view-controller sub-views使用波纹pipe的代码,如:

 - (BOOL) doesAlertViewExist { for (UIView* view in yuorviewcontroller.view.subviews) { BOOL alert = [view isKindOfClass:[UIAlertView class]]; if (alert) { return YES; } } return NO; } 

在这个方法调用之后,BOOL值为YES或NO如果是,则使用UIAlertview的Delegate将其解除:

 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; 

并把你的Actionsheet出现的代码放到didDismissWithButtonIndex方法中。

当消息到来时,首先检查是否有警报视图。

警报视图解除显示操作表。 在didDismiss...如果您现在必须显示操作表,您可以检查一个BOOL标志。

在这种情况下,你应该使用

 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 

方法而不是,

  - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

所以你的代码将是:

 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { UIActionSheet *actionSheet = ... [actionSheet showFromTabBar:self.tabBarController.tabBar]; } } 

谢谢

试试这个:for(UIWindow * w in [UIApplication sharedApplication] .windows){for(NSObject * obj in w.subviews){if([obj isKindOfClass:[UIAlertView class]]){[(UIAlertView *)obj dismissWithClickedButtonIndex:[ (UIAlertView中*)OBJ
cancelButtonIndex]animation:YES]; }}}