在UIAlertView上显示UIActionSheet

时间:2013-06-24 09:12:31

标签: iphone ios cocoa-touch uialertview uiactionsheet

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

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

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

5 个答案:

答案 0 :(得分: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之前关闭警报视图。

答案 1 :(得分:1)

对于已识别的alert-view您必须设置标记alert-view

<强>例如: -

alertviewName.tag=1;

然后你可以检查是否有警报 - 视图特别打开view-controller sub-views使用如下代码: -

- (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的代表将其关闭: -

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

并将您的操作表显示代码放入didDismissWithButtonIndex方法。

答案 2 :(得分:0)

当消息到来时,如果有警报视图,首先检查

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

答案 3 :(得分: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];
}
}

由于

答案 4 :(得分:0)

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