title: Swift / How to populate UITableViewCells
body: <p>I have a controller with a Table View on it. Have defined my cells in a view and then I bind it to the table view. (Please excuse the terminology). App builds and runs fine but none of the labels defined in the cell show anything. Entire table is blank except for the cell separators. I've followed numerous tutorials and searched SO extensively for reasons, how to create (<a href="https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson7.html#//apple_ref/doc/uid/TP40015214-CH8-SW1" rel="nofollow">Create a Table View - Apple docs</a>), settings to check, all with the same results. I've also tried cleaning, restarting Xcode, etc. This is Xcode 8/Swift 3.</p>
  
  <p>The view controller has a table view and I register the cell class like so in the viewDidLoad</p>
  
  <pre><code>self.tableView.registerCellClass(MenuTableViewCell.self) 
  </code></pre>
  
  <p>UITableViewDataSource code</p>
  
  <pre><code>func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return menusItems.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: MenuTableViewCell.identifier, for: indexPath) as! MenuTableViewCell
  
      let item = menusItems[indexPath.row]
      cell.setData(item)
      return cell
  }
  </code></pre>
  
  <p>menuItems is an array of a struct I have that is created before anything else is done</p>
  
  <p>BaseTableViewCell</p>
  
  <pre><code>open class BaseTableViewCell: UITableViewCell {
  class var identifier: String { return String.className(self) }
  
  public required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
      setup()
  }
  
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
      super.init(style: style, reuseIdentifier: reuseIdentifier)
      setup()
  }
  
  open override func awakeFromNib() {
  }
  
  open func setup() {
  }
  
  open override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
  
      // Configure the view for the selected state
  }
  
  open class func height() -&gt; CGFloat {
      return 48
  }
  
  open func setData(_ data: Any?) {
      if let menuText = data as? String {
          self.textLabel?.text = menuText
      }
      if let menuImage = data as? UIImage {
          self.imageView?.image = menuImage
      }
  }
  }
  </code></pre>
  
  <p>Table View Cell code - inherits the BaseTableViewCell</p>
  
  <pre><code>class MenuTableViewCell: BaseTableViewCell {
  
  //MARK: Properties
  @IBOutlet weak var name: UILabel!
  @IBOutlet weak var icon: UIImageView!
  
  override func awakeFromNib() {
      super.awakeFromNib()
      // Initialization code
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
      // Configure the view for the selected state
  }
  
  override func setData(_ data: Any?) {
      if let data = data as? MenuTableViewCellData {
          NSLog("menu name - %@", data.text)
          self.icon?.image = data.image
          self.name?.text = data.text
      }
  }
  }
  </code></pre>
  
  <p>All menu names are written to the debug area so the code is being executed.</p>
  
  <p>I don't know if there is hook that is missing or if something else. Please let me know if anything further is also needed. Any help is appreciated.</p>
  
  <p>Screenshots showing IBOutlets connected
  <a href="https://i.stack.imgur.com/mnx4L.png" rel="nofollow"><img src="https://i.stack.imgur.com/mnx4L.png" alt="name"></a></p>
  
  <p><a href="https://i.stack.imgur.com/SPeno.png" rel="nofollow"><img src="https://i.stack.imgur.com/SPeno.png" alt="icon"></a></p>
  
  <p>Here is the delegate and data source from the controller</p>
  
  <pre><code>extension LeftViewController : UITableViewDelegate {
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      return MenuTableViewCell.height()
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      if let menu = LeftMenu(rawValue: indexPath.row) {
          self.changeViewController(menu)
      }
  }
  
  func scrollViewDidScroll(_ scrollView: UIScrollView) {
      if self.tableView == scrollView {
  
      }
  }
  }
  
  extension LeftViewController : UITableViewDataSource {
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return menusItems.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: MenuTableViewCell.identifier, for: indexPath) as! MenuTableViewCell
  
      let item = menusItems[indexPath.row]
      cell.setData(item)
      return cell
  }
  }
  </code></pre>
  
  <p>Thanks everyone for your help. I was able to get it working. I removed the XIB file, created the layout in the view and then wired it up from there (followed <a href="http://www.apptuitions.com/uitableview-with-custom-cell-in-swift/" rel="nofollow">here</a> for how to).</p>