0

I am working with a UITableView that uses the standard UITableViewCell. I have the style set to "Right Detail" in Interface Builder.

Each cell looks correct until I scroll it out of the frame and back into the frame, at which point the detail label becomes blank.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.tableView!.dequeueReusableCellWithIdentifier("id");

    cell.detailTextLabel!.text = "value";

    return cell;
}

When I call sizeToFit(), the label appears again, but overlaps the detail indicator on the right side of the cell.

I gave tried the answers in this question: UITableViewCell detailTextLabel disappears when scrolling, but the only one that works is to subclass the UITableViewCell and I would like to, if possible, not subclass it.

Any ideas?

Community
  • 1
  • 1
Jake Chasan
  • 6,290
  • 9
  • 44
  • 90
  • Probably not related to the issue, but just a tip: replace `self.tableView!` with `tableView` and `cell.detailTextLabel!` with `cell.detailTextLabel?`. Force unwrapping should not be used when you can avoid it without excessive code. – Jorn Sep 20 '15 at 16:48

1 Answers1

0

Instead of

let cell = self.tableView!.dequeueReusableCellWithIdentifier("id");

Use

tableView.dequeueReusableCellWithIdentifier("id", forIndexPath: indexPath) as! UITableViewCell

I often had issues with dequeue cells without indexPath in previous projects. Not sure why it happens, but it is

Vitalii Gozhenko
  • 9,220
  • 2
  • 48
  • 66