iphone - #ifdef 条件未按我希望的方式工作

标签 iphone ios objective-c ipad ios-universal-app

我正在以编程方式创建 UniversalApp。在我的应用程序中,我有 2 个常量类,并且在设备的基础上我想导入我的常量类。但它总是打开“Constants_iPad”类。甚至条件为真或假。

#ifndef iPad
    #define iPad    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#endif
#ifndef iPhone
    #define iPhone  (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
#endif


#ifdef iPad  ------> always excute this condition either True of False.
    #import "Constants_iPad.h" // if device is iPad
#else
    #import "Constants_iPhone.h" // if device is iPhone
#endif

当我使用 consol 打印时

 #ifdef iPad
     NSLog(@"iPad = %d",iPad);
 #endif

如果条件错误则打印“0”,如果条件为真则打印1

最佳答案

您是否尝试过#ifdef TARGET_IPHONE 或#ifdef TARGET_IPAD 而不是#ifndef iPhone?我不确定宏 #ifndef iPhone?但除此之外,我认为不可能在导入类的预编译期间确定目标。

关于iphone - #ifdef 条件未按我希望的方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557537/

相关文章:

objective-c - 在 OSX Lion 中设置单个桌面的背景图像

iphone - 性能方面 : A lot of small PNGs or one large PNG?

ios - 使用 Swift 从字符串中检测数字年份

objective-c - 获取枚举项的总数

ios - Mapkit中如何增加userLocation标注的半径

ios - 在 Swift 中从 AppDelegate 加载嵌入到 UINavigationController 的 Controller

iphone - 如何在 iPhone 中创建一段时间的提醒,例如 30 分钟后提醒我

IOS - Swift - 向 BarButtonItem 的自定义 View 添加目标和操作

iphone - 如何加强 Java ME 生态系统

ios - Swift:变量获取以错误顺序分配的值