UIRefreshControl在iOS6中使用,但不在iOS5中使用

问题描述:

我想为iOS6用户添加UIRefreshControl,为iOS5用户添加按钮。我只想要将一个包提供给应用商店(显然),我该怎么做?UIRefreshControl在iOS6中使用,但不在iOS5中使用

我能感觉到操作系统版本

float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; 
if (ver >= 6.0) { 
    // Programmatically add UIRefreshControl. 
} 

但是,如果我想支持iOS5中,编译器不会让我用UIRefreshControl?

如果编译器不让你使用它,那么让你愚弄他。您可以(并且应该)也从操作系统版本检测切换到功能检测。总而言之:

if (NSClassFromString(@"UIRefreshControl") != Nil) { 
    id control = [[NSClassFromString(@"UIRefreshControl") alloc] init]; 
} 
+1

我会补充说苹果提供[SDK兼容性指南(https://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/cross_development/Introduction/Introduction html的#// apple_ref/DOC/UID/10000163i)。这显示了使用运行时检查来查找框架,类和方法的正确方法。代码需要检查'systemVersion'是非常罕见的。 – rmaddy 2013-02-23 15:41:27

+0

@rmaddy我懒得打开它,所以我只是问你,这是否与你的基础SDK和使用弱链接的好方法? (如果是这样,那么这也是一个很好的解决方案)。 – 2013-02-23 15:42:48

+0

@rmaddy我在哪里检查'systemVersion'? – 2013-02-23 15:43:45