Swift:Using UIRefreshControl

From Hawk Wiki
Jump to: navigation, search
//refreshControl is automatically defined in UITableViewController
var refreshControl: UIRefreshControl?
override func viewDidLoad() {
    super.viewDidLoad()
    
    refreshControl = UIRefreshControl()
    refreshControl?.addTarget(self, action: "fetch", forControlEvents: UIControlEvents.ValueChanged)
    tableView.insertSubview(refreshControl!, atIndex: 0)
}

//to stop refresh, call
if let rc = self.refreshControl {
    self.refreshControl!.endRefreshing()
}