可以遍历所有view, 如果是alert或sheet这类的弹出窗口,就自动让其关闭,代码片断如下:
- (void)dismissAllPopup:(NSArray *)subviews {
Class alert = [UIAlertView class];
Class sheet = [UIActionSheet class];
for (UIView * subview in subviews){
if ([subview isKindOfClass:alert]){
[(UIAlertView *)subview dismissWithClickedButtonIndex:[(UIAlertView *)subview cancelButtonIndex] animated:NO];
} else if ([subview isKindOfClass:sheet]){
[(UIActionSheet *)subview dismissWithClickedButtonIndex:[(UIActionSheet *)subview cancelButtonIndex] animated:NO];
} else {
[self dismissAllPopup:subview.subviews];
}
}
}