swiftuitableviewoutlet

How to subclass a UITableViewCell?


I got this old post: How to subclass UITableView? and this old video: https://www.youtube.com/watch?v=FfZGKx4BYVU but this did not help me. What I want is very simple, I got an UITableViewController with dynamic cells. I want to outlet those cells. This is only possible if I "subclass" it. I made another file what looks like this:

import UIKit

class CreateChannelCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

But I still can not add those outlets from the UITableViewController to this file. My cells needs to be dynamic. I think I am only missing one step, but what step is that? Thank you.


Solution

  • That is the right way to subclass. But if you are using Storyboards or Xib files then you need to reference the CreateChannelCell in the UITableView that you created and where the CreateChannelCell is located.

    You need to select the cell and then go to CustomClass and write the name of your class there ... in this case CreateChannelCell

    Here you need to go at your Cell and declare <code>CreateChannelCell</code>

    If you are not using Storyboards or Xib's please see the answer provided by Code Different