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

Con*_*oob 1 iphone objective-c uikit ios

我想为iOS6用户添加一个UIRefreshControl,为iOS5用户添加一个按钮.我只希望有一个包我发送到应用程序商店(很明显)所以我该怎么做?

我能感觉到操作系统版本

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

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

小智 8

如果编译器不允许你使用它,那么让你欺骗他.您可以(也应该)从OS版本检测切换到功能检测.总而言之:

if (NSClassFromString(@"UIRefreshControl") != Nil) {
    id control = [[NSClassFromString(@"UIRefreshControl") alloc] init];
}
Run Code Online (Sandbox Code Playgroud)