0

Here is the cell I want to reuse.

enter image description here

And there is a related cell class.

class FlightTransitTBCell: UITableViewCell {
@IBOutlet weak var abovebullet: UILabel!
@IBOutlet weak var bottomBullet: UILabel!

@IBOutlet weak var upBullet: UILabel!
@IBOutlet weak var downBullet: UILabel!


@IBOutlet weak var lblAboveTime: UILabel!
@IBOutlet weak var lblButtomTime: UILabel!

@IBOutlet weak var lblUpTime: UILabel!
@IBOutlet weak var lblDownTime: UILabel!

@IBOutlet weak var lblAboveAirPort: UILabel!
@IBOutlet weak var lblButtomAirPort: UILabel!

@IBOutlet weak var lblDownAirPort: UILabel!
@IBOutlet weak var lblUpAirPort: UILabel!

@IBOutlet weak var viaDown: UILabel!
@IBOutlet weak var viaUp: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    downBullet.text = "\u{2022}"
    upBullet.text = "\u{2022}"
    abovebullet.text = "\u{2022}"
    bottomBullet.text = "\u{2022}"

    downBullet.font = UIFont(name: getAppFont(), size: 20)
    upBullet.font = UIFont(name: getAppFont(), size: 20)
    abovebullet.font = UIFont(name: getAppFont(), size: 40)
    bottomBullet.font = UIFont(name: getAppFont(), size: 40)

}
}

Following is my xib, which contain a tableview that I'm trying to display above cell.

enter image description here

And I register the cell from the xib class like this.

tableView.register(FlightTransitTBCell.self, forCellReuseIdentifier: "TransitCell")

then dequeue from tableview like this..

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

    if let transitCell = tableView.dequeueReusableCell(withIdentifier: "TransitCell") as? FlightTransitTBCell{
        transitCell.awakeFromNib()
        transitCell.selectionStyle = .none
        transitCell.setTransitView(indexPath.row, firstRoute, lastRoute)
        transitCell.setBullet(outward_[indexPath.row])
        if indexPath.row == 2 {
            transitCell.backgroundColor = UIColor.green
        }
        return transitCell
    }

    return UITableViewCell()
}

I got the cell and it means my registration is working. But all my outlets are being nil and giving me error. I don't know what I'm doing is proper way of not. I'm not sure. This is my first time of doing like that and stuck here.

enter image description here

Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54
  • Unrelated but never call `awakeFromNib` yourself. The method is exclusively called by the framework. It you need to share code put it into a custom method. – vadian May 06 '19 at 08:30
  • I removed that code but outcome is the same. – Zin Win Htet May 06 '19 at 08:32
  • Your cell should be in a separate xib file if you want to reuse it across the project. Take a look at this [answer](https://stackoverflow.com/a/1939305/8314394) – Starsky May 06 '19 at 08:36
  • I know, that's why I wrote *unrelated*. – vadian May 06 '19 at 08:41

0 Answers0