Dismissing UIAlertViews when entering background state

前端 未结 12 1639
心在旅途
心在旅途 2020-12-02 06:44

Apple recommends dismissing any UIAlertViews/UIActionSheets when entering background state in iOS 4. This is to avoid any confusion on the user\'s part when he

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 07:15

    A totally different approach is a recursive search.

    Recursive function for your application delegate

    - (void)checkViews:(NSArray *)subviews {
        Class AVClass = [UIAlertView class];
        Class ASClass = [UIActionSheet class];
        for (UIView * subview in subviews){
            if ([subview isKindOfClass:AVClass]){
                [(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
            } else if ([subview isKindOfClass:ASClass]){
                [(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
            } else {
                [self checkViews:subview.subviews];
            }
        }
    }
    

    Calling it from the applicationDidEnterBackground procedure

    [self checkViews:application.windows];
    

提交回复
热议问题