【发布时间】:2014-11-22 17:56:12
【问题描述】:
据报道,此代码在 here 和 here 有效,但我似乎无法使其有效。
IBOutlets 与故事板中的对象相关联。
prototypeCell 被命名,所以我可以将它与dequeueReusableCellWithIdentifier 一起使用,它的自定义类属性设置为commentCell。
第一个错误(我可以解决,但上面的链接都不需要它,这让我觉得我做错了什么。我是对的吗?):
Overriding method with selector 'initWithStyle:reuseIdentifier:' has incompatible type '(UITableViewCellStyle, String) -> commentCell'
第二个错误(有趣的错误):
'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'`
单元类代码:
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)
}
}
初始化代码:
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
}
【问题讨论】:
标签: ios uitableview swift