使用swift

时间:2015-08-06 15:02:03

标签: swift parsing refresh

我知道如何使用pull刷新以及如何制作刷新按钮。我只是想知道是否有人知道如何或可以将我链接到一个教我如何自动刷新页面的页面。像每15秒自动刷新一样。

2 个答案:

答案 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()
}