2012-10-16 69 views

回答

1

您可以使用singleton design pattern並作出一個全局對象。但是總的來說,全局變量/對象/單例是暗示你的設計有些問題是錯誤的。

創建單是這樣的:

+ (CardPainter*) sharedPainter { 
    static CardPainter* sp; 
    static dispatch_once_t token; 
    dispatch_once(&token, ^{ 
     sp = [[CardPainter alloc] init]; 
    }); 
    return sp; } 
+0

嘿親愛的,我有一個混亂。我應該在哪裏創建'cardPainter'類的對象來全局使用它? –