MACBaseCell.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // MACBaseCell.h
  3. // MACProject
  4. //
  5. // Created by MacKun on 15/12/18.
  6. // Copyright © 2015年 MacKun. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "CellDataAdapter.h"
  10. @class MACBaseCell;
  11. @protocol MACBaseCellDelegate <NSObject>
  12. @optional
  13. /**
  14. * CustomCell's event.
  15. *
  16. * @param cell CustomCell type class.
  17. * @param event Event data.
  18. */
  19. - (void)macBaseCellCell:(MACBaseCell *)cell event:(id)event;
  20. @end
  21. @interface MACBaseCell : UITableViewCell
  22. #pragma mark - Propeties.
  23. /**
  24. * CustomCell's delegate.
  25. */
  26. @property (nonatomic, weak) id <MACBaseCellDelegate> delegate;
  27. /**
  28. * CustomCell's dataAdapter.
  29. */
  30. @property (nonatomic, weak) CellDataAdapter *dataAdapter;
  31. /**
  32. * CustomCell's data.
  33. */
  34. @property (nonatomic, weak) id data;
  35. /**
  36. * CustomCell's indexPath.
  37. */
  38. @property (nonatomic, weak) NSIndexPath *indexPath;
  39. /**
  40. * TableView.
  41. */
  42. @property (nonatomic, weak) UITableView *tableView;
  43. /**
  44. * Controller.
  45. */
  46. @property (nonatomic, weak) UIViewController *controller;
  47. /**
  48. * Cell is showed or not, you can set this property in UITableView's method 'tableView:willDisplayCell:forRowAtIndexPath:' & 'tableView:didEndDisplayingCell:forRowAtIndexPath:' at runtime.
  49. */
  50. @property (nonatomic) BOOL display;
  51. #pragma mark - Method you should overwrite.
  52. /**
  53. * Setup cell, override by subclass.
  54. */
  55. - (void)setupCell;
  56. /**
  57. * Build subview, override by subclass.
  58. */
  59. - (void)buildSubview;
  60. /**
  61. * Load content, override by subclass.
  62. */
  63. - (void)loadContent;
  64. /**
  65. * Calculate the cell's from data, override by subclass.
  66. *
  67. * @param data Data.
  68. *
  69. * @return Cell's height.
  70. */
  71. + (CGFloat)cellHeightWithData:(id)data;
  72. #pragma mark - Useful method.
  73. /**
  74. * Update the cell's height with animated or not, before you use this method, you should have the weak reference 'tableView' and 'dataAdapter', and this method will update the weak reference dataAdapter's property cellHeight.
  75. *
  76. * @param height The new cell height.
  77. * @param animated Animated or not.
  78. */
  79. - (void)updateWithNewCellHeight:(CGFloat)height animated:(BOOL)animated;
  80. /**
  81. * Selected event, you should use this method in 'tableView:didSelectRowAtIndexPath:' to make it effective.
  82. */
  83. - (void)selectedEvent;
  84. #pragma mark - Constructor method.
  85. /**
  86. * Create the cell's dataAdapter.
  87. *
  88. * @param reuseIdentifier Cell reuseIdentifier, can be nil.
  89. * @param data Cell's data, can be nil.
  90. * @param height Cell's height.
  91. * @param type Cell's type.
  92. *
  93. * @return Cell's dataAdapter.
  94. */
  95. + (CellDataAdapter *)dataAdapterWithCellReuseIdentifier:(NSString *)reuseIdentifier data:(id)data
  96. cellHeight:(CGFloat)height type:(NSInteger)type;
  97. /**
  98. * Create the cell's dataAdapter.
  99. *
  100. * @param reuseIdentifier Cell reuseIdentifier, can be nil.
  101. * @param data Cell's data, can be nil.
  102. * @param height Cell's height.
  103. * @param width Cell's width.
  104. * @param type Cell's type.
  105. *
  106. * @return Cell's dataAdapter.
  107. */
  108. + (CellDataAdapter *)dataAdapterWithCellReuseIdentifier:(NSString *)reuseIdentifier data:(id)data
  109. cellHeight:(CGFloat)height cellWidth:(CGFloat)cellWidth
  110. type:(NSInteger)type;
  111. /**
  112. * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string.
  113. *
  114. * @param data Cell's data, can be nil.
  115. * @param height Cell's height.
  116. * @param type Cell's type.
  117. *
  118. * @return Cell's dataAdapter.
  119. */
  120. + (CellDataAdapter *)dataAdapterWithData:(id)data cellHeight:(CGFloat)height type:(NSInteger)type;
  121. /**
  122. * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string.
  123. *
  124. * @param data Cell's data, can be nil.
  125. * @param height Cell's height.
  126. *
  127. * @return Cell's dataAdapter.
  128. */
  129. + (CellDataAdapter *)dataAdapterWithData:(id)data cellHeight:(CGFloat)height;
  130. /**
  131. * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string.
  132. *
  133. * @param data Cell's data, can be nil.
  134. *
  135. * @return Cell's dataAdapter.
  136. */
  137. + (CellDataAdapter *)dataAdapterWithData:(id)data;
  138. /**
  139. * Convenient method to set some weak reference.
  140. *
  141. * @param dataAdapter CellDataAdapter's object.
  142. * @param data Data.
  143. * @param indexPath IndexPath.
  144. * @param tableView TableView.
  145. */
  146. - (void)setWeakReferenceWithCellDataAdapter:(CellDataAdapter *)dataAdapter data:(id)data
  147. indexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView;
  148. @end