AvaJ AvaJ - 7 months ago 34
Swift Question

UIRefreshControl after 3 seconds endRefreshing

I have a function that updates a

UITableView
by using
UIRefreshControl
. But I want that it after 3 second the function call
EndRefreshing
.

func updateMyTable(){

tableView.reloadData()

//refreshTable.endRefreshing()
}

Answer

The best delay method I know available on swift:

func dispatchDelay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
}

Your code will be:

func updateMyTable(){
    tableView.reloadData()
    dispatchDelay(3.0) {
       self.refresh.endRefreshing()
    }
}