我正在以编程方式创建 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/