UITableView+CellClass.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "UITableView+CellClass.h"
  9. #import "CellDataAdapter.h"
  10. #import "MACBaseCell.h"
  11. @implementation UITableView (CellClass)
  12. - (void)registerCellsClass:(NSArray <CellClassType *> *)cellClasses {
  13. for (int i = 0; i < cellClasses.count; i++) {
  14. CellClassType *cellClass = cellClasses[i];
  15. [self registerClass:NSClassFromString(cellClass.classString) forCellReuseIdentifier:cellClass.reuseIdentifier];
  16. }
  17. }
  18. - (MACBaseCell *)dequeueAndLoadContentReusableCellFromAdapter:(CellDataAdapter *)adapter indexPath:(NSIndexPath *)indexPath {
  19. MACBaseCell *cell = [self dequeueReusableCellWithIdentifier:adapter.cellReuseIdentifier];
  20. [cell setWeakReferenceWithCellDataAdapter:adapter data:adapter.data indexPath:indexPath tableView:self];
  21. [cell loadContent];
  22. return cell;
  23. }
  24. - (MACBaseCell *)dequeueAndLoadContentReusableCellFromAdapter:(CellDataAdapter *)adapter indexPath:(NSIndexPath *)indexPath
  25. controller:(UIViewController *)controller {
  26. MACBaseCell *cell = [self dequeueReusableCellWithIdentifier:adapter.cellReuseIdentifier];
  27. cell.controller = controller;
  28. [cell setWeakReferenceWithCellDataAdapter:adapter data:adapter.data indexPath:indexPath tableView:self];
  29. [cell loadContent];
  30. return cell;
  31. }
  32. @end
  33. @implementation CellClassType
  34. + (instancetype)cellClassTypeWithClassString:(NSString *)classString reuseIdentifier:(NSString *)reuseIdentifier {
  35. NSParameterAssert(NSClassFromString(classString));
  36. CellClassType *type = [[[self class] alloc] init];
  37. type.classString = classString;
  38. type.reuseIdentifier = reuseIdentifier;
  39. return type;
  40. }
  41. + (instancetype)cellClassTypeWithClassString:(NSString *)classString {
  42. NSParameterAssert(NSClassFromString(classString));
  43. CellClassType *type = [[[self class] alloc] init];
  44. type.classString = classString;
  45. type.reuseIdentifier = classString;
  46. return type;
  47. }
  48. @end