我想知道是否有人能够告诉我,从头开始一个新应用程序,我将如何组织一个通用的(iPhone/iPad)iOS应用程序。我注意到在xCode Beta中使用默认模板,它为您提供了一个共享的AppDelegate和iPhone和iPad的子类appdelegates。

现在,您如何放入逻辑来确定要使用哪个应用程序委托(delegate),如何知道要实例化和使用哪个应用程序委托(delegate)(因为默认模板未说明)。如果我要在iPhone appDelegate中编写代码,我怎么知道该操作仅适用于iPhone iOS?

最佳答案

使用以下代码

id<UIApplicationDelegate> delegate = [[UIApplication sharedApplication] delegate];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    AppDelegate_iPad *appDelegate = (AppDelegate_iPad *) delegate;
else
    AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *) delegate;

每当您需要访问代理。

10-07 19:55
查看更多