Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class MyCell: UITableViewCell {
- final let myCustomView: UIView
- override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
- self.myCustomView = UIView()
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- self.contentView.addSubview(self.myCustomView)
- }
- // Deserialize your object here
- // required = subclasses of that class have to implement it too
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- //its called when
- //Its own bounds (not frame) changed
- //The bounds of one of its direct subviews changed
- //A subview is added to the view or removed from the view
- //set the frame rectangles of your subviews directly
- //setNeedsLayout(): If you want to force a layout update, call the setNeedsLayout() method instead to do so prior to the next drawing update.
- //layoutIfNeeded(): If you want to update the layout of your views immediately, call the layoutIfNeeded() method
- //use both setNeedsLayouts - layoutIfNeeded for instant use
- final override func layoutSubviews() {
- super.layoutSubviews()
- self.myCustomView.frame = self.contentView.bounds
- // intrinsic content size changes
- // super.layoutSubviews() The second call to super.layoutSubviews() is optional but may be required
- //if the intrinsic conent size of the view changes
- }
- //For performance reasons, you should only reset attributes of the cell
- //that are not related to content
- //for example, alpha, editing, and selection state.
- final override func prepareForReuse() {
- super.prepareForReuse()
- self.content.prepareForReuse()
- }
- //The table view's delegate in tableView(_:cellForRowAt:)
- //should always reset all content when reusing a cell.
- //use cell.configure(mynewRowDataHere)
- final func configure(/*userID: Int*/)
- //do the setup here
- self.setNeedsLayout()
- }
- }
Add Comment
Please, Sign In to add comment