Search code examples
swiftxcodexcode10

Table view still showing basic even after making it custom in Xcode 10.1


I have done everything as done before in my previous projects in Xcode 8.1... But simulator shows basic empty table rows even after making it custom. tried everything including delegate and datasource in viewdidload.

Here's the project link https://drive.google.com/open?id=1hBR1cH5vr-sS4gLB-VBfF6iJPYKD59rd

(Sorry for that google drive upload)

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tblNames: UITableView!

var names = ["lonrvc","ktbfse","lnrset"]

override func viewDidLoad() {
    super.viewDidLoad()      
    self.tblNames.delegate = self
    self.tblNames.dataSource = self  
    self.tblNames.reloadData()   
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return names.count       
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CustomTableViewCell        
    cell.lblName.text = names[indexPath.row]
    self.tblNames.reloadData()        
    return cell
      }
  }

I just want to show the array on custom cell.(not on basic cell)


Solution

  • Took a look at your project, just set some constraints to your label in the storyboard and it should work fine, oh and delete the line self.tblNames.reloadData() from cellForRowAt.

    enter image description here