以编程方式触发时,UIRefreshControl不刷新 [英] UIRefreshControl not refreshing when triggered programmatically

查看:56
本文介绍了以编程方式触发时,UIRefreshControl不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在加载视图时显示刷新控件,以表明我正在从Parse获取数据.当应用程序运行时,刷新控件应能正常工作,但是我无法以编程方式从应用程序中的任何位置触发刷新控件.这是似乎无法运行的代码:

I am trying to show a refresh control right when the view loads to show that I am getting getting data from Parse. The refresh control works as it should when the app is running, but I cannot get it to fire programmatically from anywhere in my app. This is the code that does not appear to run:

 override func viewDidAppear(animated: Bool) {
    self.refresher.beginRefreshing()
 }

这不仅不会运行,而且在应用程序中包含代码会更改刷新控件的属性.当我在应用程序中包含此代码并显示用户交互的刷新器时,刷新控件没有通常具有的属性标题,也没有运行应有的代码.

Not only does this not run, but having the code in the app changes the attributes of the refresh control. When I have this code in the app, and show the refresher from user interaction, the refresh control does not have its attributed title as it usually does nor does it run the code that it should.

推荐答案

以下是在10.3上进行的扩展:

Here's an extension working on 10.3:

extension UIRefreshControl {
    func refreshManually() {
        if let scrollView = superview as? UIScrollView {
            scrollView.setContentOffset(CGPoint(x: 0, y: scrollView.contentOffset.y - frame.height), animated: false)
        }
        beginRefreshing()
        sendActions(for: .valueChanged)
    }
}

这篇关于以编程方式触发时,UIRefreshControl不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆