user6268517
user6268517

Reputation:

UIViewController refresh fails when refresh data function is called in Swift 4

When I want to refresh my tableView from the Main Thread it gives me this error: Thread 1: fatal error unexpectedly found nil while unwrapping an optional value which meant that the tableView doesn't have an outlet to the ViewController. But the tableView is linked to the ViewController. What am I doing wrong?

This is the error:

enter image description here

This is the ViewController and outlets:

enter image description here

DispatchQueue.main.sync(){
      print("Requestlist Finished Downloading")

      if(Constants.activeViewController == 1){
          self.tableViewRequestlist .reloadData()
          Constants.busyRequest = false
      }
      else{
          Constants.busyRequest = false
     }
      Constants.requestlistDownloaded = true
  }

Upvotes: 1

Views: 84

Answers (2)

Nitish
Nitish

Reputation: 14123

Use self.tableViewRequestlist.reloadData() instead of
self.tableViewRequestlist .reloadData()
Though Xcode doesn't throw a compile time error for this but compiler will look for variable name without space.

Upvotes: 1

Peeyush karnwal
Peeyush karnwal

Reputation: 642

One possibility is that the viewcontroller gets deinitilized due to some reason before loading any views. To check that, put a breakpoint in viewDidLoad() method and another in the deinit() method.

If this is not the case then the IBoutlets must have not been linked with the viewcontroller.

Upvotes: 0

Related Questions