UITableView+HYBCacheHeight.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // UITableView+HYBCacheHeight.m
  3. // CellAutoHeightDemo
  4. //
  5. // Created by huangyibiao on 16/1/22.
  6. // Copyright © 2016年 huangyibiao. All rights reserved.
  7. //
  8. #import "UITableView+HYBCacheHeight.h"
  9. #import <objc/runtime.h>
  10. static const void *__hyb_tableview_cacheCellHeightKey = "__hyb_tableview_cacheCellHeightKey";
  11. static const void *__hyb_tableview_reuse_cells_key = "__hyb_tableview_reuse_cells_key";
  12. @implementation UITableView (HYBCacheHeight)
  13. - (NSMutableDictionary *)hyb_cacheCellHeightDict {
  14. NSMutableDictionary *dict = objc_getAssociatedObject(self, __hyb_tableview_cacheCellHeightKey);
  15. if (dict == nil) {
  16. dict = [[NSMutableDictionary alloc] init];
  17. objc_setAssociatedObject(self,
  18. __hyb_tableview_cacheCellHeightKey,
  19. dict,
  20. OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  21. }
  22. return dict;
  23. }
  24. - (NSMutableDictionary *)hyb_reuseCells {
  25. NSMutableDictionary *cells = objc_getAssociatedObject(self, __hyb_tableview_reuse_cells_key);
  26. if (cells == nil) {
  27. cells = [[NSMutableDictionary alloc] init];
  28. objc_setAssociatedObject(self,
  29. __hyb_tableview_reuse_cells_key,
  30. cells,
  31. OBJC_ASSOCIATION_RETAIN);
  32. }
  33. return cells;
  34. }
  35. @end