2010-11-15 76 views
1

以下是我設置我的應用程序的方式。我有一個根視圖,它在viewDidLoad方法中加載子視圖的頂部。在子視圖中,我有一個按鈕,單擊它時會隱藏自身並顯示根視圖。一切都很好,但我討厭有一個視圖已加載,但沒有被使用。我試圖把一個方法,這是否委託:無法訪問委託中的方法

[theLaunch release]; 

...其中theLaunch是我的子視圖。

此方法位於我的代表中,名爲hidetheLaunch

然後我試圖從子視圖中調用此方法:

[[UIApplication sharedApplication].delegate hidetheLaunch]; 

但它說-hidetheLaunch not found in protocol

我這樣做全錯嗎?

在此先感謝!

回答

2

您需要首先UIApplicationDelegate您的特定委託的類型:

[((MyAppDelegate *) [UIApplication sharedApplication].delegate) hidetheLaunch]; 
+0

當我代替我的委託名稱爲您提供的代碼,它說,它沒有聲明。我需要'#導入'委託嗎? – 2010-11-15 21:15:54

+0

是的,並使用正確的名稱。 – 2010-11-15 21:50:16

+0

那麼,每當我導入委託時,它就會在我的應用程序中導致錯誤。我只是決定完全跳過整個事情。 :) – 2010-11-15 22:37:15