I want to create a float window above the main window, so code like blow. I use a fake singleton pattern to manage a UIWindow. Because I don't want other object retain the window. The code:
@class testWindow;
static testWindow *singletonSelf;
static dispatch_once_t once;
@implementation testWindow
+ (testWindow *)sharedWindow {
dispatch_once(&(once), ^{
singletonSelf = [[testWindow alloc] initWithFrame:CGRectMake(200,200,200,200)];
});
return singletonSelf;
}
+ (void)dismiss {
singletonSelf = nil;
once = 0;
}
...
- (void)closeButtonClicked {
self.hidden = YES;
[testWindow dismiss];
}
There is a button on the window. The method '-closeButtonClicked' will called when the button clicked. When -closeButtonClicked called, I will set the Window hidden property to YES and set singletonSelf,once to nil for the future to create a new window.
But when I did this, the window did not dealloc immediately. The windows property of the [UIApplication sharedApplication] even contain the window I want to release.
Until I tap the screen(any where),the windows property of the [UIApplication sharedApplication] remove the window,than the window will released.
I want to remove the window from windows immediately when I call the +dismiss method.
THX for help. This is my first question on StackOverFlow~~~ Ignore my poor english~
I know the fake singleton is now suggest, but I this is a good choice on this situation. If u have other choice please tell share with me~