Skip to content

Instantly share code, notes, and snippets.

@icanswiftabit
Last active May 23, 2016 10:58
Show Gist options
  • Save icanswiftabit/0cf4d2068186c5f8dae2c8dd05158e8c to your computer and use it in GitHub Desktop.
Save icanswiftabit/0cf4d2068186c5f8dae2c8dd05158e8c to your computer and use it in GitHub Desktop.
  1. Create new class extending UITableViewCell with xib
  2. In ViewController register nib for this class

Example

DirectionViewCell.swift

class DirectionViewCell: UITableViewCell{
  @IBOutlet var stopNameLabel: UILabel!
  @IBOutlet var tagLabel: UILabel!
  @IBOutlet private var headerView: UIView!
  static let identifier = "DirectionCell"
  override func awakeFromNib() {
      super.awakeFromNib()
      // Initialization code
      print(tagLabel) //If you do everything correct then this line shouldn't tchrow nil exception
  }
  override func setSelected(selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
      // Configure the view for the selected state
  }
}

TableViewController.swift

override func viewDidLoad() {
  super.viewDidLoad()
  // Do any additional setup after loading the view, typically from a nib.
  let nib = UINib(nibName: "DirectionViewCell", bundle: nil)
  self.tableView.registerNib(nib, forCellReuseIdentifier: DirectionViewCell.identifier)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment