uitableview的UIRefreshControl不仅仅适用于iphone 6

时间:2016-12-19 05:32:37

标签: ios swift uitableview uirefreshcontrol

实际上,除了IPhone-6之外,所有设备都能正常工作。请帮我解决这个问题。

我的代码是

var refreshControl = UIRefreshControl()

        self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
        self.tableView.addSubview(self.refreshControl)


func refresh(_ sender:AnyObject) {
    if self.appDel.isNetworkEnabled
    {
        DispatchQueue.main.async {
            if(self.page < Int(self.total_pages)! )
            {
                self.page = self.page + 1
                self.fetchMessageApiCall()
            }
        }
    }
    else
    {
        self.singletonObj.showAlert("", message: "No Internet")
    }

    self.refreshControl.endRefreshing()
}

3 个答案:

答案 0 :(得分:2)

当您从API获取数据时,可能应该放置此self.refreshControl.endRefreshing()

答案 1 :(得分:1)

只需像这样分配刷新控制器:

    let tableViewControler = UITableViewController()
    tableViewControler.tableView = self.tableView
    self.refreshController = UIRefreshControl()
    self.refreshController.tintColor = UIColor(red: 87.0/255.0, green: 53.0/255.0, blue: 129.0/255.0, alpha: 1.0)
    let attributedString = NSAttributedString(string: "Refresh")
    self.refreshController.attributedTitle = attributedString
    self.refreshController.addTarget(self, action:#selector(self.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
    tableViewControler.refreshControl = self.refreshController

希望这会有所帮助

答案 2 :(得分:0)

SWIFT 3.0

我在IOS 10及以上版本中遇到过这个问题,并使用以下代码

解决了这个问题
refreshControl = UIRefreshControl()

refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: #selector(refresh(sender:)), for: UIControlEvents.valueChanged)
    if #available(iOS 10.0, *) {
        self.gigListTableView.refreshControl = refreshControl
    } else {
        // Fallback on earlier versions
        self.gigListTableView.addSubview(refreshControl)
    }