我正在使用Cocos2D,並且需要訪問UIView中的父方法,該UIView從另一個類添加到UIViewController。我的層次結構是這樣的:從Cocos2D類訪問UIView方法
分公司1:窗口> viewController.view> glView> joinedMapsScene> joinedMapsLayer
分公司2:窗口> viewController.view> foregroundLabelView
當我的標籤類曾經是Cocos2D中的一部分,訪問是通過做這樣的事情很簡單:
JoinedMapsScene *joinedMapsScene = (JoinedMapsScene*)self.parent; [joinedMapsScene.tetraCounter incTetras:-1];
但現在我需要從joinedMapsLayer調用foregroundLabelView中的方法。這可能不是一個很大的cocos2D問題,但我仍然對這類東西感到困惑。
所以這意味着我不再可以將foregroundLabelView作爲子視圖添加到viewController.view? – VagueExplanation 2012-02-08 00:01:34
Nono!您可以!但是你也可以從應用程序委託給它分配一個指針。通過這種方式,您可以通過從委託中調用指向它的指針來檢索它! – 2012-02-08 00:31:38
視圖總是一樣的!而且它只有一個!但是你有兩種方法來訪問它:從它的類(和你說的孩子)以及從AppDelegate(從所有類,因爲你可以從所有類中檢索AppDelegate)。 – 2012-02-08 00:35:57