2

Although setting subtitle style for cell, but detailTextLabel has not still showed.

let cellIdentifier = "homeFeedItem"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell(style: .subtitle,     reuseIdentifier: cellIdentifier)
cell.textLabel?.text = self.arrItems[indexPath.row]["title"]
cell.detailTextLabel?.text = self.arrItems[indexPath.row]["desc"]
cell.imageView?.image = UIImage(named: self.arrItems[indexPath.row]["icon"]!)

I tried print self.arrItems[indexPath.row]["desc"]. It's ok. Please help me fix it.

Ryan Tran
  • 467
  • 6
  • 16
  • Did you set the style in Interface Builder? Use the method `dequeueReusableCell(withIdentifier:forIndexPath:)` to get always a valid non-optional reused cell. – vadian Nov 03 '16 at 05:12
  • thanks for your reply! I set it programmatically. – Ryan Tran Nov 03 '16 at 08:20
  • If you set it programmatically – which I don't understand why you make things more complicated – you have to ensure that the style of all cells is set respectively. – vadian Nov 03 '16 at 08:29

1 Answers1

0

ok i got it. originally answered by Scott Berrevoets

According to this SO post, registering UITableViewCell means all cells will be instantiated with the default style. Subtitled and right and left detail cells are not available with registerClass:forCellReuseIdentifier:.

Community
  • 1
  • 1
ha100
  • 1,563
  • 1
  • 21
  • 28