2012-11-11 58 views
0

我無法理解這樣的代碼做什麼:應用程序的委託在IOS

AppDelegate *appDelegate = 
[[UIApplication sharedApplication] delegate]; 

有人可以解釋給我好嗎?

+0

你究竟需要什麼解釋?它與objective-c中的其他方法相同; '[UIApplication sharedApplication]'返回['UIApplication'](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplication_Class/Reference/Reference.html)和'[...委託]'返回一個['id '](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html),它存儲在一個變量中。 – Kevin

回答

0

您正在獲取指向應用程序委託的指針。

[UIApplication sharedApplication] 

你的一個指針應用實例回報(單實例,只有一個對象的實例是允許的,並且它是由「sharedApplication」方法返回)。

然後,「委託」返回此UIApplication實例的代理,通常是在應用程序的AppDelegate.m和AppDelegate.h文件中實現,它是AppDelegate類的實現。

0

每個iOS應用程序都有一個應用程序委託。你問的代碼給你提供了這個代表的參考。有關更多詳細信息,請參閱文檔UIApplication delegateUIApplicationDelegate

相關問題