通用iPhone / iPad AppDelegate [英] Universal iPhone/iPad AppDelegate

查看:87
本文介绍了通用iPhone / iPad AppDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was wondering if anyone would be able to tell me, starting a new app from scratch, how would I organise having a universal (iPhone/iPad) iOS app. I noticed using the default template with the xCode Beta, it gives you both a shared AppDelegate and subclassed appdelegates for iPhone and iPad.

现在,您如何通过逻辑来确定要使用哪个应用委托,如何知道哪个应用实例化并使用默认模板不进行状态。如果我要在iPhone appDelegate中写一下,我怎么知道这只适用于iPhone iOS?

Now, how do you put in the logic to determine which app delegate to use, how does it know which one to instantiate and work with as the default template doesnt state. If I were to write in the iPhone appDelegate, how do i know that this will only run for the iPhone iOS for example?

推荐答案

使用以下代码

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;

这篇关于通用iPhone / iPad AppDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆