我知道如何使用pull刷新以及如何制作刷新按钮。我只是想知道是否有人知道如何或可以将我链接到一个教我如何自动刷新页面的页面。像每15秒自动刷新一样。
答案 0 :(得分:1)
从这开始:
@IBOutlet weak var yourButton: UIButton!
var timer: NSTimer!
var refresher: UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
yourButton.addTarget(self, action: "refresh:", forControlEvents: .TouchUpInside)
refresher = UIRefreshControl()
refresher.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
timer = NSTimer.scheduledTimerWithTimeInterval(15.0, target: self, selector:"refreshEvery15Secs", userInfo: nil, repeats: true)
}
func refreshEvery15Secs(){
// refresh code
}
func refresh(sender: AnyObject){
refreshEvery15Secs() // calls when ever button is pressed
}
答案 1 :(得分:-1)
创建NSTimer
每15秒触发一次
let timer = NSTimer.scheduledTimerWithTimeInterval(15, target: self, selector: "refreshData:", userInfo: nil, repeats: true)
在回调函数中进行刷新
func refreshData(timer: NSTimer){
refreshControl.beginRefreshing()
}