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 is named so I can use it with dequeueReusableCellWithIdentifier
and it's custom class attribute is set to commentCell
.
First Error (which I can solve, but neither of the links above needed it, which makes me think I'm doing something wrong. Am I right?):
Overriding method with selector 'initWithStyle:reuseIdentifier:' has incompatible type '(UITableViewCellStyle, String) -> commentCell'
Second Error (the interesting error):
'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'`
Cell Class Code:
class commentCell: UITableViewCell {
@IBOutlet weak var authorLabel: UILabel!
@IBOutlet weak var commentLabel: UITextView!
init(style: UITableViewCellStyle, reuseIdentifier: String) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Initialization code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
println(comments[indexPath.row])
var cell = self.tableView.dequeueReusableCellWithIdentifier("prototypeCell") as commentCell
cell.commentLabel.text = comments[indexPath.row]["comment"] as NSString
cell.authorLabel.text = comments[indexPath.row]["fromid"] as NSString
return cell
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…