// // MACBaseCell.h // MACProject // // Created by MacKun on 15/12/18. // Copyright © 2015年 MacKun. All rights reserved. // #import #import "CellDataAdapter.h" @class MACBaseCell; @protocol MACBaseCellDelegate @optional /** * CustomCell's event. * * @param cell CustomCell type class. * @param event Event data. */ - (void)macBaseCellCell:(MACBaseCell *)cell event:(id)event; @end @interface MACBaseCell : UITableViewCell #pragma mark - Propeties. /** * CustomCell's delegate. */ @property (nonatomic, weak) id delegate; /** * CustomCell's dataAdapter. */ @property (nonatomic, weak) CellDataAdapter *dataAdapter; /** * CustomCell's data. */ @property (nonatomic, weak) id data; /** * CustomCell's indexPath. */ @property (nonatomic, weak) NSIndexPath *indexPath; /** * TableView. */ @property (nonatomic, weak) UITableView *tableView; /** * Controller. */ @property (nonatomic, weak) UIViewController *controller; /** * Cell is showed or not, you can set this property in UITableView's method 'tableView:willDisplayCell:forRowAtIndexPath:' & 'tableView:didEndDisplayingCell:forRowAtIndexPath:' at runtime. */ @property (nonatomic) BOOL display; #pragma mark - Method you should overwrite. /** * Setup cell, override by subclass. */ - (void)setupCell; /** * Build subview, override by subclass. */ - (void)buildSubview; /** * Load content, override by subclass. */ - (void)loadContent; /** * Calculate the cell's from data, override by subclass. * * @param data Data. * * @return Cell's height. */ + (CGFloat)cellHeightWithData:(id)data; #pragma mark - Useful method. /** * 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. * * @param height The new cell height. * @param animated Animated or not. */ - (void)updateWithNewCellHeight:(CGFloat)height animated:(BOOL)animated; /** * Selected event, you should use this method in 'tableView:didSelectRowAtIndexPath:' to make it effective. */ - (void)selectedEvent; #pragma mark - Constructor method. /** * Create the cell's dataAdapter. * * @param reuseIdentifier Cell reuseIdentifier, can be nil. * @param data Cell's data, can be nil. * @param height Cell's height. * @param type Cell's type. * * @return Cell's dataAdapter. */ + (CellDataAdapter *)dataAdapterWithCellReuseIdentifier:(NSString *)reuseIdentifier data:(id)data cellHeight:(CGFloat)height type:(NSInteger)type; /** * Create the cell's dataAdapter. * * @param reuseIdentifier Cell reuseIdentifier, can be nil. * @param data Cell's data, can be nil. * @param height Cell's height. * @param width Cell's width. * @param type Cell's type. * * @return Cell's dataAdapter. */ + (CellDataAdapter *)dataAdapterWithCellReuseIdentifier:(NSString *)reuseIdentifier data:(id)data cellHeight:(CGFloat)height cellWidth:(CGFloat)cellWidth type:(NSInteger)type; /** * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string. * * @param data Cell's data, can be nil. * @param height Cell's height. * @param type Cell's type. * * @return Cell's dataAdapter. */ + (CellDataAdapter *)dataAdapterWithData:(id)data cellHeight:(CGFloat)height type:(NSInteger)type; /** * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string. * * @param data Cell's data, can be nil. * @param height Cell's height. * * @return Cell's dataAdapter. */ + (CellDataAdapter *)dataAdapterWithData:(id)data cellHeight:(CGFloat)height; /** * Create the cell's dataAdapter, the CellReuseIdentifier is the cell's class string. * * @param data Cell's data, can be nil. * * @return Cell's dataAdapter. */ + (CellDataAdapter *)dataAdapterWithData:(id)data; /** * Convenient method to set some weak reference. * * @param dataAdapter CellDataAdapter's object. * @param data Data. * @param indexPath IndexPath. * @param tableView TableView. */ - (void)setWeakReferenceWithCellDataAdapter:(CellDataAdapter *)dataAdapter data:(id)data indexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView; @end