self.tableView.reloadData() not working in Swift self.tableView.reloadData() not working in Swift ios ios

self.tableView.reloadData() not working in Swift


You'll need to reload the table on the UI thread via:

//swift 2.3dispatch_async(dispatch_get_main_queue(), { () -> Void in    self.tableView.reloadData()})//swift 5DispatchQueue.main.async{    self.tableView.reloadData()}

Follow up:An easier alternative to the connection.start() approach is to instead use NSURLConnection.sendAsynchronousRequest(...)

//NSOperationQueue.mainQueue() is the main threadNSURLConnection.sendAsynchronousRequest(NSURLRequest(URL: url), queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in    //check error    var jsonError: NSError?    let json: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.allZeros, error: &jsonError)    //check jsonError    self.collectionView?.reloadData()}

This doesn't allow you the flexibility of tracking the bytes though, for example you might want to calculate the progress of the download via bytesDownloaded/bytesNeeded


You have just to enter:

First a IBOutlet:

@IBOutlet var appsTableView : UITableView

Then in a Action func:

self.appsTableView.reloadData()


If your connection is in background thread then you should update UI in main thread like this

self.tblMainTable.performSelectorOnMainThread(Selector("reloadData"), withObject: nil, waitUntilDone: true)

As I have mentioned here

Swift 4:

self.tblMainTable.performSelector(onMainThread: #selector(UICollectionView.reloadData), with: nil, waitUntilDone: true)