Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. final class MyCell: UITableViewCell {
  2.  
  3. final let myCustomView: UIView
  4.  
  5. override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
  6. self.myCustomView = UIView()
  7. super.init(style: style, reuseIdentifier: reuseIdentifier)
  8. self.contentView.addSubview(self.myCustomView)
  9. }
  10.  
  11. // Deserialize your object here
  12. // required = subclasses of that class have to implement it too
  13. required init?(coder aDecoder: NSCoder) {
  14. fatalError("init(coder:) has not been implemented")
  15. }
  16.  
  17. //its called when
  18. //Its own bounds (not frame) changed
  19. //The bounds of one of its direct subviews changed
  20. //A subview is added to the view or removed from the view
  21. //set the frame rectangles of your subviews directly
  22. //setNeedsLayout(): If you want to force a layout update, call the setNeedsLayout() method instead to do so prior to the next drawing update.
  23. //layoutIfNeeded(): If you want to update the layout of your views immediately, call the layoutIfNeeded() method
  24. //use both setNeedsLayouts - layoutIfNeeded for instant use
  25. final override func layoutSubviews() {
  26. super.layoutSubviews()
  27.  
  28. self.myCustomView.frame = self.contentView.bounds
  29. // intrinsic content size changes
  30.  
  31. // super.layoutSubviews() The second call to super.layoutSubviews() is optional but may be required
  32. //if the intrinsic conent size of the view changes
  33. }
  34.  
  35. //For performance reasons, you should only reset attributes of the cell
  36. //that are not related to content
  37. //for example, alpha, editing, and selection state.
  38. final override func prepareForReuse() {
  39. super.prepareForReuse()
  40.  
  41. self.content.prepareForReuse()
  42. }
  43.  
  44. //The table view'€™s delegate in tableView(_:cellForRowAt:)
  45. //should always reset all content when reusing a cell.
  46. //use cell.configure(mynewRowDataHere)
  47. final func configure(/*userID: Int*/)
  48. //do the setup here
  49. self.setNeedsLayout()
  50. }
  51. }
Add Comment
Please, Sign In to add comment