为什么UIRefreshControl跳跃? [英] Why UIRefreshControl jumping?
问题描述
我尝试将UIRefreshControl与swift 1.2一起使用,除了用户界面外,工作正常。这是跳跃,我不知道为什么。
以下是我正在做的事情:
I try to use the UIRefreshControl with swift 1.2 and works fine except the UI. It is jumping and I dont know why. Here is what I am doing:
class ViewController: UIViewController {
var refreshControl:UIRefreshControl!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
}
func refresh(sender:AnyObject) {
// Code to refresh table view
}
}
你可以从这里下载我的poc项目:
POC项目
And you can download my poc project from here: POC project
当你拉下tableView时,突然跳了一下。有谁知道为什么?
While you pull down the tableView, suddenly jump a little bit down. Has anybody any idea why?
如果我使用UITableViewController,它工作正常,但我不想使用这个UI对象。我想在UIViewController中使用一个简单的UITableView。
If I use with UITableViewController, It works fine but I dont want to use this UI object. I would like to use a simple UITableView in a UIViewController.
推荐答案
我找到了一个解决方案,它有效:
I found a solution, it works:
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
var tableViewC = UITableViewController()
tableViewC.refreshControl = self.refreshControl
self.tableView = tableViewC.tableView
self.view.addSubview(self.tableView)
}
这篇关于为什么UIRefreshControl跳跃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!