0

I don't have a prototype cell in IB. I'm initializing the cell in code.

let mycell = UITableViewCell(style: .Default, reuseIdentifier: "reuseIdentifier")
mycell.textLabel!.text = "main text"
mycell.detailTextLabel!.text = "test"

The mycell.textLabel!.text call works fine. But the mycell.detailTextLabel!.text call crashes the app because mycell.detailTextLabel is nil. Is there something else I need to do for that part to work?

4thSpace
  • 43,672
  • 97
  • 296
  • 475

1 Answers1

1

I ran into the same problem - this helped.

How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?

Use something like:

cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
                reuseIdentifier: "identifier")
Community
  • 1
  • 1
knopch1425
  • 709
  • 6
  • 19
  • If you type only the dot, Subtitle doesn't appear in the hints. You have to type out UITableViewCellStyle then dot and it is there. Do you know why? – 4thSpace Dec 21 '15 at 16:43
  • I don't, but I ran into this: http://stackoverflow.com/questions/30025110/autocomplete-for-leading-dot-doesnt-work-in-swift – knopch1425 Dec 22 '15 at 00:09