简体   繁体   English

在UIAlertView上显示UIActionSheet

[英]Showing UIActionSheet over UIAlertView

For a specific server notification I am supposed to show an UIActionSheet. 对于特定的服务器通知,我应该显示一个UIActionSheet。 But problem here is when that event comes, at the same time if any UIAlertView already showing on any view controller, it make the UIActionSheet disabled( After pressed ok for alert view I am not able to select anything on view controller , view got disabled because of UIActionSheet). 但是这里的问题是当该事件发生时,如果同时在任何视图控制器上已经显示任何UIAlertView,则会使UIActionSheet禁用(在为警报视图按下ok之后,我无法在视图控制器上选择任何内容,因为视图被禁用,因为UIActionSheet)。 Anyone faced this kind of problem, Any idea how to solve it? 任何人都面临此类问题,有什么解决方案的想法吗?

I have tried by dismissing alert view before showing action sheet, however which alert view do I need to dismiss as I have many alert view in many controller. 我已经尝试过在显示操作表之前关闭警报视图,但是由于我在许多控制器中都有许多警报视图,因此我需要关闭哪个警报视图。 All are local to that controllers. 所有都在该控制器本地。 How to solve this problem. 如何解决这个问题呢。

Note: Same problem won't come for iPod, as it wont allow to click ok before responding to UIActionSheet. 注意: iPod不会出现相同的问题,因为它不允许在响应UIActionSheet之前单击“确定”。

Take a Global Alert view named it as activeAlertView. 取一个名为AlertAlertView的全局警报视图。 Now when you show a alert view please check that alert view and then show and assign. 现在,当您显示警报视图时,请检查该警报视图,然后显示并分配。 Like 喜欢

declare a property in .h and synthesize it 在.h中声明属性并进行合成

@property (nonatomic, retain) UIAlertView *activeAlertView;

then use the below code when try to show an alert. 然后在尝试显示警报时使用以下代码。

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

this way your activeAlertview will keep the current aler view's reference and before show the actionSheet dismiss the alert view. 这样,您的activeAlertview将保留当前aler视图的引用,并在显示actionSheet之前关闭警报视图。

For Identified which alert-view you must set Tag or alert-view . 对于“确定哪个alert-view您必须设置Tagalert-view

Ex:- 例如:-

alertviewName.tag=1;

Then you can check is there alert-view Open in Particular view-controller sub-views use bellow code like:- 然后,您可以检查是否有警报视图在特定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;

}

After this method called you get BOOL value YES or NO If Yes then dismiss it using UIAlertview's Delegate:- 调用此方法后,您将获得BOOL值YES或NO。如果是,则使用UIAlertview的Delegate将其关闭:-

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

and put your Actionsheet appear code into didDismissWithButtonIndex method. 并将您的“动作表”显示代码放入didDismissWithButtonIndex方法中。

When the message comes, first check if there is an alert view. 消息到来时,首先检查是否有警报视图。

Show the action sheet after the alert view is dismissed. 关闭警报视图 ,显示操作表。 In didDismiss... you can check a BOOL flag if you now have to show the action sheet or not. didDismiss... ,如果现在必须显示操作表,则可以检查BOOL标志。

In this case, you should use 在这种情况下,您应该使用

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

method rather than, 方法而不是

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

so your code wil be: 因此您的代码将是:

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

Thanks 谢谢

try this: for (UIWindow* w in [UIApplication sharedApplication].windows) { for (NSObject* obj in w.subviews) { if ([obj isKindOfClass:[UIAlertView class]]) { [(UIAlertView*)obj dismissWithClickedButtonIndex:[(UIAlertView*)obj 尝试以下操作:对于([UIApplication sharedApplication] .windows中的UIWindow * w){对于(w.subviews中的NSObject * obj){如果([[obj isKindOfClass:[UIAlertView class]]]){[((UIAlertView *)obj dismissWithClickedButtonIndex:[ (UIAlertView *)obj
cancelButtonIndex] animated:YES]; cancelButtonIndex]动画:是]; } } } }}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM