新增一個變數
var refresher:UIRefreshControl?
初始化他
override func viewDidLoad() {
super.viewDidLoad()
// 初始化
refresher = UIRefreshControl()
// 設定title
refresher?.attributedTitle = NSAttributedString(string: "正在努力加載中")
// 設定執行的selector
// TableViewController -> 是這個 class 的名字
// refresh -> function name
refresher?.addTarget(self, action: #selector(TableViewController.refresh), for: UIControlEvents.valueChanged)
// add subview
tableView.addSubview(refresher!)
//print(currentuser)
getAccount()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
func refresh(){
getAccount()
refresher?.endRefreshing()
}
沒有留言:
張貼留言