-1

I have I UITableView and I am trying to get detailTextLabel to appear with my textLabel, but when I run my code, all I see the textLabel and the detailTextLabel does not appear, here is my code:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath)

        print(self.array[indexPath.row])

        cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String)

        cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String)

        return cell
    }

and here are the delegate methods:

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

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
user979331
  • 11,039
  • 73
  • 223
  • 418

1 Answers1

-1

Your are doing nothing wrong.This issue may be the Datasource dand Delegate method assignment. Generally, It is set by Storybord, but sometime it does not work property.

So, you can try it by setting it grammatically.

tableView.delegate = self
tableView.dataSource = self

Hope this work. Good luck!

Harish Singh
  • 765
  • 1
  • 12
  • 23