-2

I'm having a problem with my UITableView custom cell.

This is the UITableView code:

var contactName = ["Papa", "Mummy", "Ajay", "Deepak", "My"]
var phoneNumber = ["657464567", "354636346", "5436346", "6345634643", "5645634656"]

// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return contactName.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! myTableViewCell
    cell.name.text = contactName[indexPath.row]
    return cell
}

And this is my custom cell code:

@IBOutlet weak var name: UILabel!

I double checked that everything is connected properly so please help me figure out why I'm having this problem.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Dilip Tilonia
  • 63
  • 1
  • 6

1 Answers1

0

You have used UITableViewController so you need to return number of sections as 1. So change the code like below :

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

To

 override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
Vinodh
  • 5,262
  • 4
  • 38
  • 68
  • i've removed that function so it default is 1 and i do write like this alway by the way i also tried this is (above one which you suggested) i don't this is an issue here – Dilip Tilonia Sep 15 '17 at 10:58
  • Then did you get any crash in the log. Please post that – Vinodh Sep 15 '17 at 11:17