swiftでぐるぐる更新を実装する(UIRefreshControl)

UIRefreshControlはTableViewをしたに引っ張って更新するやつ。
  twitterのこんな感じのやつ

f:id:kinoue3:20161024233015p:plain



override func viewDidLoad() {
    self.refreshControl = UIRefreshControl()
    refreshControll.attributedTitle = NSAttributedString(string: "更新")
    refreshControll.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
    tableView.addSubview(refreshControll)      
}

func refresh()  {
    tableView.reloadData()
    // ぐるぐるを終了させる
    refreshControll.endRefreshing()        
}