对半单身人士有任何缺点吗?

时间:2014-01-15 18:14:57

标签: objective-c singleton

我刚刚解决了一个非常奇怪的问题,我需要这个类的行为有点像单身而不是真的。这是一段代码片段

@implementation HMFPicturePreviewModalPanel

__weak static UIViewController            *presentingInventoryViewController = nil;
       static HMFPicturePreviewModalPanel *sharedPicturePreviewModalPanel    = nil;

+(void)showPopupWithImage:(UIImage *)image withStartPoint:(CGPoint)startPoint withStartView:(UIView *)startView {

    //this checks if there is already a panel visible.
    if (![presentingInventoryViewController.view viewWithTag:kHMFPicturePreviewModalPanelTag]) {
        sharedPicturePreviewModalPanel = [[HMFPicturePreviewModalPanel alloc] initWithFrame:presentingInventoryViewController.view.bounds withimage:image];
        [presentingInventoryViewController.view addSubview:sharedPicturePreviewModalPanel];
        [sharedPicturePreviewModalPanel showFromPoint:[startView convertPoint:startPoint toView:presentingInventoryViewController.view]];
    }
}

+(void)changePresentingInventoryViewController:(UIViewController *)newInventoryViewController {
    [sharedPicturePreviewModalPanel removeFromSuperView];
    presentingInventoryViewController = newInventoryViewController;
}

+(void)removePresentingInventoryViewController {
    [sharedPicturePreviewModalPanel removeFromSuperView];
    presentingInventoryViewController = nil;
}

这被称为半单身吗?屏幕上一次只会出现其中一种。我不得不每次重新创建它才能工作,因此我不能只做一个单身人士。

此解决方案的缺点是什么? 还有一个__weak静态变量吗?

0 个答案:

没有答案