Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override init in subclassed UITableViewCell

I want to ovrride init(frame: CGRect) in a subclassed UITableViewCell.

override init(frame: CGRect) {
   super.init(frame: CGRect)
}

But this throws an error: Initializer does not ovrride a designated initializer from its super class, I did something wrong?

like image 540
ZeroChow Avatar asked Feb 24 '16 15:02

ZeroChow


1 Answers

For an UITableViewCell, you should be overriding this one:

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}

See documentation.

If you would like to be able to vary cells' frame, you should look into delegate methods like:

  • tableView(_:heightForRowAtIndexPath:) for row height
  • tableView(_:indentationLevelForRowAtIndexPath:) for row indent

See documentation for UITableViewDelegate.

like image 182
konrad.bajtyngier Avatar answered Oct 06 '22 13:10

konrad.bajtyngier