覆盖子类UITableViewCell中的init

Zer*_*how 4 uitableview ios swift

我想init(frame: CGRect)在子类UITableViewCell中使用ovrride .

override init(frame: CGRect) {
   super.init(frame: CGRect)
}
Run Code Online (Sandbox Code Playgroud)

但这引发了一个错误:Initializer does not ovrride a designated initializer from its super class我做错了什么?

kon*_*ier 10

对于一个UITableViewCell,你应该压倒这个:

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}
Run Code Online (Sandbox Code Playgroud)

文档.

如果您希望能够改变单元格的框架,您应该查看委托方法,如:

  • tableView(_:heightForRowAtIndexPath:) 行高
  • tableView(_:indentationLevelForRowAtIndexPath:) 用于行缩进

文档UITableViewDelegate.