Multiple AlertViews - Remove the alertview that is behind another alertview

会有一股神秘感。 提交于 2020-01-03 04:34:05

问题


I think this scenario should be weird one but i am stuck up with this.

I am having a view lets say View1, which will show one or more alertviews.Alerts are stacked one above the other if they are untouched. The problem comes here. If i click the top most alert ,it should take me to a complete new view lets say View2. And it does. Now i am getting the remaining alerts still shown in View2. I do not want this to happen . How can i auto dismiss the pending alerts created from View1 which are currently being shown in View2 ?

Any help or any idea is really appreciated..

Thanks


回答1:


Not quite the answer to your question that you wanted, but...

Why do you have so many alerts? It sounds like you might be overusing them. Apple is quite clear in its Human Interface Guidelines about how you should use UIAlerts:

Avoid creating unnecessary alerts.

These alerts are usually unnecessary if they:

  • Merely increase the visibility of some information, especially information that is related to the standard functioning of your application.

Instead, you should design an eye-catching way to display the information that harmonizes with your app’s style.

  • Update users on tasks that are progressing normally.

Instead, consider using a progress view or an activity indicator to provide progress-related feedback to users (these methods of feedback are described in “Progress View” and “Activity Indicator”).

  • Ask for confirmation of user-initiated actions.

To get confirmation for an action the user initiated, even a potentially risky action such as deleting a contact, you should use an action sheet.

  • Inform users of errors or problems about which they can do nothing.

Although it might be necessary to use an alert to tell users about a critical problem they can’t fix, it’s better to integrate such information into the UI, if possible. For example, instead of telling users every time a server connection fails, display the time of the last successful connection.

If you're overusing alerts: don't. Then your original question may become moot.




回答2:


Try this,

    UIAlertView *autoAlertView = [[UIAlertView alloc] initWithTitle:@"Auto-dismissed Alert" message:@"This alert will be dismissed in 5 seconds." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
    [self performSelector:@selector(dismissAlert:) withObject:autoAlertView afterDelay:5];
    [autoAlertView show];
    [autoAlertView release];

-(void)dismissAlert:(UIAlertView *)alert {
    [alert dismissWithClickedButtonIndex:0 animated:YES];
}



回答3:


You can dismiss the other UIAlertViews programmatically using:

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

You'll need to store a reference to them at creation to do this.




回答4:


Thanks, guys! I wrote my own substitute for UIAlertView. I'm putting halftransparent UIView with frame (0, 0, 320, 480) to avoid user interaction while my custom alert still says "Please wait", and above this background view I'm putting this custom alert which is just basic UIView with UIActivityIndicatorView on it

P.S. Don't judge me for my english, i'm russian



来源:https://stackoverflow.com/questions/5188101/multiple-alertviews-remove-the-alertview-that-is-behind-another-alertview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!