'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'`

前端 未结 4 1974
夕颜
夕颜 2020-12-15 03:46

This code has reportedly worked here and here, but I can\'t seem to make it work.

The IBOutlets are hooked up to their objects in the storyboard. The prototypeCell i

4条回答
  •  别那么骄傲
    2020-12-15 04:24

    Not sure why you need a custom UITableViewCell class if you are using storyboard with a prototype cell. You can just drop your labels and textviews into the cell and work with them.

    If you are working from a xib then I get it, but you only need:

    class commentCell: UITableViewCell {
        @IBOutlet weak var authorLabel: UILabel!
        @IBOutlet weak var commentLabel: UITextView!
    
    }
    

    You would then register the xib in the TableView class with:

    override func viewDidLoad() {
            super.viewDidLoad()
    
            self.tableView.registerNib(UINib(nibName: "commentCell", bundle: nil),
                forCellReuseIdentifier: "reuseIdentifier")
        }
    

    Regarding the cellForRowAtIndexPath function, the syntax is now a little modified:

    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    
     var cell = self.tableView.dequeueReusableCellWithIdentifier("prototypeCell") as commentCell
    
    
    
            return cell
        }
    

    If you want to post to github, we can help make modifications. It's hard to be specific without seeing more of the code.

提交回复
热议问题