Skip to content

Commit d5e2156

Browse files
committed
make weak reference to old window
1 parent a1c326c commit d5e2156

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@interface SIAlertView ()
4040

4141
@property (nonatomic, strong) NSMutableArray *items;
42-
@property (nonatomic, strong) UIWindow *oldKeyWindow;
42+
@property (nonatomic, weak) UIWindow *oldKeyWindow;
4343
@property (nonatomic, strong) UIWindow *alertWindow;
4444
@property (nonatomic, assign, getter = isVisible) BOOL visible;
4545

@@ -308,6 +308,10 @@ - (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type ha
308308

309309
- (void)show
310310
{
311+
if (self.isVisible) {
312+
return;
313+
}
314+
311315
self.oldKeyWindow = [[UIApplication sharedApplication] keyWindow];
312316

313317
if (![[SIAlertView sharedQueue] containsObject:self]) {
@@ -318,10 +322,6 @@ - (void)show
318322
return; // wait for next turn
319323
}
320324

321-
if (self.isVisible) {
322-
return;
323-
}
324-
325325
if ([SIAlertView currentAlertView].isVisible) {
326326
SIAlertView *alert = [SIAlertView currentAlertView];
327327
[alert dismissAnimated:YES cleanup:NO];
@@ -445,8 +445,13 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
445445
}
446446
}
447447

448-
[self.oldKeyWindow makeKeyWindow];
449-
self.oldKeyWindow.hidden = NO;
448+
449+
UIWindow *window = self.oldKeyWindow;
450+
if (!window) {
451+
window = [UIApplication sharedApplication].windows[0];
452+
}
453+
[window makeKeyWindow];
454+
window.hidden = NO;
450455
}
451456

452457
#pragma mark - Transitions

0 commit comments

Comments
 (0)