2013-06-24 68 views
0

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

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

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

回答

2

将全局警报视图命名为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视图的引用,并在显示actionSheet之前关闭警报视图。

+0

如果警报视图显示在其中一个子视图控制器中,该怎么办...... – Newbee

+0

在您的子视图控制器中创建一个类似的全局警报视图,并使用相同的逻辑,如有警报解除它,显示新警报并保留其全局变量中的引用。重要的是你有权访问子视图控制器的全局属性。 – Ashim

+0

雅是多数民众赞成我最后的选择...我一直在尝试任何其他可能性来处理这种情况下...我会更新,如果有任何感谢。 – Newbee

0

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

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

+0

雅我已经明白了你的观点,但问题是我需要关闭哪个警报视图......父视图控制器正在接收服务器事件,它也显示动作表..但之前在任何子视图控制器警报视图可能已显示..我怎么知道哪些警报视图和如何解雇..我是否需要发送消息给所有的孩子? – Newbee

0

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

- (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]; 
} 
} 

感谢

+0

它是一个来电通知...我迫不及待地点击UIAlertview的确定按钮,我需要通过给予高优先级来显示操作表。 – Newbee

1

对于鉴定出alert-view您必须设置标签alert-view

例如: -

alertviewName.tag=1; 

然后你可以检查是否有警报的视图打开像特别view-controllersub-views使用波纹管代码: -

- (BOOL) doesAlertViewExist { 

     for (UIView* view in yuorviewcontroller.view.subviews) { 
      BOOL alert = [view isKindOfClass:[UIAlertView class]]; 

      if (alert) 
      { 
      return YES; 
      } 

     } 
     return NO; 

} 

调用此方法后,你会得到BOOL值是或否如果是,则使用UIAlertview的代表将其解散: -

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

并将您的Actionsheet出现的代码放入didDismissWithButtonIndex方法中。

0

尝试: 为(一个UIWindow * w的[UIApplication的sharedApplication] .windows) { 为(在w.subviews NSObject的* OBJ) { 如果([OBJ isKindOfClass:[UIAlertView中类]]) {(UIAlertView *)obj dismissWithClickedButtonIndex:[(UIAlertView *)obj
cancelButtonIndex] animated:YES]; } } }