Sre*_*ree 5 iphone xcode objective-c ios ios5
在我的应用程序中,当应用程序转到后台时,我需要删除窗口中可见的任何警报.但问题是,我不想忽略它
[alert dismissWithClickedButtonIndex:0 animated:YES]
Run Code Online (Sandbox Code Playgroud)
因为,它会触发clickedButtonAtIndexDelegate并调用一个方法.当应用程序转到后台时,我不想避免这种情况.
我通过使用以下代码从窗口的子视图中删除alertView成功完成了它
for (UIWindow *window in [UIApplication sharedApplication].windows) {
for (UIView *view in [window subviews]) {
if ([view isKindOfClass:[UIAlertView class]]) {
[view removeFromSuperview];
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是,_UIAlertNormalizingOverlayWindow仍然存在,它会阻止用户Interaction.I需要删除_UIAlertNormalizingOverlayWindow也从我的窗口.请帮我这样做,或者请建议任何替代方案来实现解决方案.
虽然这不是一个非常干净的解决方案(假设 ivarBOOL _backgroundAlertFlag
- (void)applicationDidEnterBackground:(UIApplication *)application {
_backgroundAlertFlag = YES;
// find your UIAlertView as you are doing already
[alert dismissWithClickedButtonIndex:0 animated:NO];
_backgroundAlertFlag = NO;
}
Run Code Online (Sandbox Code Playgroud)
然后在你的UIAlertViewDelegate方法中:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if( !_backgroundAlertFlag )
{
// handle alert processing normally here
}
// other wise ignore (just dismiss)
}
Run Code Online (Sandbox Code Playgroud)