用于检测 iPad 的预处理器指令
我在头文件中声明了一些常量,这些常量需要根据它是 iPad 应用程序还是 iPhone 应用程序而有所不同。我该怎么做?
IE
#ifdef ISIPAD
static NSString myconst = @"ipad!";
#else
static NSString myconst = @"iphone!";
#endif
I declare some constants in a header file which need to be different depending on whether it is an iPad or an iPhone app. How would I do this?
i.e.
#ifdef ISIPAD
static NSString myconst = @"ipad!";
#else
static NSString myconst = @"iphone!";
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在编写一款通用应用程序,则无法进行编译时检查,因为编译器会为 iPhone 和 iPad 生成一个可执行文件。如果您有适用于 iPhone 和 iPad 的单独应用程序(具有共享代码库),为什么不自己适当地#define ISIPAD。否则,您必须在运行时进行检查。
您可以将它们设置为全局变量,在您的应用程序启动时通过检查您正在运行的设备然后进行适当的设置来初始化它们。
If you're writing an universal app, you can't do a compile time check since the compiler generates one executable for both the iPhone and the iPad. If you've got separate apps for iPhone and iPad (with a shared codebase), why not just #define ISIPAD appropriately yourself. Otherwise, you have to do a check at runtime.
You could make them global variables that get initialized when your app starts up by checking to see which device you're running on then setting them appropriately.