title: How to update textLabel inside a tableview cell iOS Swift
body: <p>I have created a table view programatically, below is the code, when I tried to update the label using a completion handler the value is not displayed in the table view cell. </p>
  
  <p>Could someone please suggest me how I could update the textLabel in the <strong>languagesSpokenCell</strong> in my tableview ? I have spent several hours trying to get this resolved, but I am still unable to.</p>
  
  <p>Here is the completion Handler that is called after the user selects the languages that he speaks.</p>
  
  <pre><code>func showLanguagesSpoken(_ languagesSpoken: [String]?){
          languagesSpokenString = (languagesSpoken?.joined(separator: ", "))!
          languagesSpokenCell.textLabel?.text = languagesSpokenString
         //*** In the below print statement the value is printed correctly but the text label is not updated in the cell. 
          print("languagesSpokenCell.textLabel?.text: \(languagesSpokenCell.textLabel?.text)") 
              self.tableView.reloadData()
          }
  </code></pre>
  
  <p>Here I am Programatically creating table view cells</p>
  
  <pre><code>// FOR TABLE VIEW - Tableview cells
      var tableView: UITableView  =   UITableView()
  
      var firstNameCell: UITableViewCell = UITableViewCell()
      var lastNameCell: UITableViewCell = UITableViewCell()
      var languagesSpokenCell: UITableViewCell = UITableViewCell()
      
      
      // FOR TABLE VIEW - Textfields
      var firstName: UITextField = UITextField()
      var lastName: UITextField = UITextField()
  
  
  
  override func loadView() {
          super.loadView()
          
          // construct first name cell, section 0, row 0
          self.firstNameCell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5)
          self.firstName = UITextField(frame: self.firstNameCell.contentView.bounds.insetBy(dx: 15, dy: 0))
          self.firstName.placeholder = "First Name"
          self.firstNameCell.addSubview(self.firstName)
          
          // construct last name cell, section 0, row 1
          self.lastNameCell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5)
          self.lastName = UITextField(frame: self.lastNameCell.contentView.bounds.insetBy(dx: 15, dy: 0))
          self.lastName.placeholder = "Last Name"
          self.lastNameCell.addSubview(self.lastName)
          
          self.languagesSpokenCell.textLabel?.text = "Languages Spoken"
          self.languagesSpokenCell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5)
          self.languagesSpokenCell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
    
      }
  </code></pre>
  
  <p>Below are the Table view methods</p>
  
  <pre><code>func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 2
      }
  
      // Return the number of rows for each section in your static table
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          switch(section) {
          case 0: return 2    // section 0 has 2 rows
          case 1: return 1    // section 1 has 1 row
          default: fatalError("Unknown number of sections")
          }
      }
  
      // Return the row for the corresponding section and row
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          switch(indexPath.section) {
          case 0:
              switch(indexPath.row) {
              case 0: return self.firstNameCell   // section 0, row 0 is the first name
              case 1: return self.lastNameCell    // section 0, row 1 is the last name
              default: fatalError("Unknown row in section 0")
              }
          case 1:
              switch(indexPath.row) {
              case 0: return self.languagesSpokenCell
              }
          default: fatalError("Unknown section")
          }
      }
  
      // Customize the section headings for each section
      func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -&gt; String? {
          switch(section) {
          case 0: return "Profile"
          case 1: return "Languages Spoken"
          default: fatalError("Unknown section")
          }
      }
  
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          let row     = indexPath.row
          let section = indexPath.section
  
          let currentCell = tableView.cellForRow(at: indexPath) as! UITableViewCell
  
  
         if section == 4 &amp;&amp; row == 0 {
              // The user has clicked on languages spoken cell
              self.performSegue(withIdentifier: "showLanguageSelectionTVC", sender: self)
          }
  
          print("Printing celll text label: \(currentCell.textLabel!.text)")
  
      }
  </code></pre>
  
  <p>Below are the constraints that I have set in the <code>ViewDidLoad()</code> method.</p>
  
  <pre><code>    tableView = UITableView(frame: CGRect.zero, style: UITableViewStyle.grouped)
      tableView.delegate      =   self
      tableView.dataSource    =   self
      tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
      self.view.addSubview(self.tableView)
  
      // Disabling automatic constraints
  
      tableView.translatesAutoresizingMaskIntoConstraints                     = false
  
      // Do any additional setup after loading the view.
  
      let viewDict = [
          "tableView"                 : tableView
      ]
  
  
      // Setting Constraints for the table view
      self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[tableView]|", options: [], metrics: nil, views: viewDict))
      self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[tableView]|", options: [], metrics: nil, views: viewDict))
  </code></pre>