0

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.

4

2 回答 2

2

You need to register your custom class with the table view.

If the cell is on the same scene as your table view:

tableView.register(MyCustomCell.self, forCellReuseIdentifier: "cell")

If you designed it on a different nib ( say MyCustomCell.xib):

let nib = UINib(nibName:@"MyCustomCell" bundle: .main)
tableView.register(nib, forCellReuseIdentifier: "cell")
于 2017-02-13T21:13:00.273 回答
1

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

于 2017-02-13T21:13:20.527 回答