2015-03-19 72 views
0

我雨燕上+ SpriteKit
工作我在課堂上鍵入功能正常的函數調用

class func cellPurchasedSuccessfullyUpdateLabel() 
{ 
    // ShopScene.cellsLabelUpdates() // I want call currentCellUpdate function here .. Or Scene name is ShopScene 
} 

func currentCellUpdate() 
{ 

} 

這些在同一場景「ShopScene」這兩個功能的問題。我無法在「cellPurchasedSuccessfullyUpdateLabel」中調用「currentCellUpdate」。 任何人可以幫助我如何訪問本地功能CLASS類型功能。

回答

0

類方法的要點是它們不綁定到任何實例,而是綁定到類型本身,這意味着您不能引用實例方法,因爲在那裏沒有實例。但作爲一種變通方法,您可以在self通過作爲cellPurchasedSuccessfullyUpdateLabel參數,假設你的代碼包含在A類:

class A { 

    class func cellPurchasedSuccessfullyUpdateLabel(instanceOfA: A) { 
     instanceOfA.currentCellUpdate() 
    } 

    func currentCellUpdate() { 

    } 
} 

但這種方法需要A一個實例,當你調用類方法。

相關問題