【问题标题】:UIRefreshControl conditionally declare for ios 5 and belowUIRefreshControl 有条件地为 ios 5 及更低版本声明
【发布时间】:2012-10-16 15:06:09
【问题描述】:

我正在使用UIRefreshControl 下拉刷新 iOS 6,它正在工作。我正在使用自定义委托在完成时进行更新,在我调用的那个方法中,

[self->refresh endRefreshing];

我已经声明了,

UIRefreshControl *refresh;

在接口文件中,因为我无法调用

[self->refresh endRefreshing] 

来自自定义委托方法。

这一切都适用于 iOS 6,但在较低版本的 iOS 上,它会失败,因为 `UIRefreshControl' 仅适用于 iOS 6 及更高版本。

我如何有条件地声明它们以便它在 iOS6 及更低版本上都可以使用?

【问题讨论】:

    标签: iphone ios ios4


    【解决方案1】:
    1. 将实例变量声明为id。
    2. 在使用时将变量转换为UIRefreshControl *。
    3. 在您使用它的地方周围,使用if (NSClassFromString(@"UIRefreshControl") != Nil) { ... } 确保UIRefreshControl 可用。

    【讨论】:

    • Jesper,谢谢你的回复,我试过了。这是我尝试的错误代码pastebin.com/ZGXXu5Hh
    • 你必须使用 iOS 6 SDK。
    • Jasper,Base sdk 设置为 ios 6,但仍然出现同样的错误。
    【解决方案2】:

    或者使用 [[UIDevice currentDevice] systemVersion] 和自定义拉取刷新,例如这个:https://github.com/leah/PullToRefresh

    【讨论】:

      【解决方案3】:

      https://github.com/instructure/CKRefreshControl 是 UIRefreshControl 的直接替代品,它在 iOS6+ 上使用 UIRefreshControl,在以前的版本上使用自定义的下拉刷新逻辑。我与它的开发没有任何关系,但它工作得很好!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-11-12
        • 2021-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-09
        • 1970-01-01
        相关资源
        最近更新 更多