FLEXTableView.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // FLEXTableView.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 4/17/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXTableView.h"
  9. #import "FLEXUtility.h"
  10. #import "FLEXSubtitleTableViewCell.h"
  11. #import "FLEXMultilineTableViewCell.h"
  12. #import "FLEXKeyValueTableViewCell.h"
  13. #import "FLEXCodeFontCell.h"
  14. FLEXTableViewCellReuseIdentifier const kFLEXDefaultCell = @"kFLEXDefaultCell";
  15. FLEXTableViewCellReuseIdentifier const kFLEXDetailCell = @"kFLEXDetailCell";
  16. FLEXTableViewCellReuseIdentifier const kFLEXMultilineCell = @"kFLEXMultilineCell";
  17. FLEXTableViewCellReuseIdentifier const kFLEXMultilineDetailCell = @"kFLEXMultilineDetailCell";
  18. FLEXTableViewCellReuseIdentifier const kFLEXKeyValueCell = @"kFLEXKeyValueCell";
  19. FLEXTableViewCellReuseIdentifier const kFLEXCodeFontCell = @"kFLEXCodeFontCell";
  20. #pragma mark Private
  21. @interface UITableView (Private)
  22. - (CGFloat)_heightForHeaderInSection:(NSInteger)section;
  23. - (NSString *)_titleForHeaderInSection:(NSInteger)section;
  24. @end
  25. @implementation FLEXTableView
  26. + (instancetype)flexDefaultTableView {
  27. #if FLEX_AT_LEAST_IOS13_SDK
  28. if (@available(iOS 13.0, *)) {
  29. #if !TARGET_OS_TV
  30. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
  31. #else
  32. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  33. #endif
  34. } else {
  35. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  36. }
  37. #else
  38. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  39. #endif
  40. }
  41. #pragma mark - Initialization
  42. + (id)groupedTableView {
  43. #if FLEX_AT_LEAST_IOS13_SDK
  44. if (@available(iOS 13.0, *)) {
  45. #if !TARGET_OS_TV
  46. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
  47. #else
  48. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  49. #endif
  50. } else {
  51. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  52. }
  53. #else
  54. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  55. #endif
  56. }
  57. + (id)plainTableView {
  58. return [[self alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  59. }
  60. + (id)style:(UITableViewStyle)style {
  61. return [[self alloc] initWithFrame:CGRectZero style:style];
  62. }
  63. - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
  64. self = [super initWithFrame:frame style:style];
  65. if (self) {
  66. [self registerCells:@{
  67. kFLEXDefaultCell : [FLEXTableViewCell class],
  68. kFLEXDetailCell : [FLEXSubtitleTableViewCell class],
  69. kFLEXMultilineCell : [FLEXMultilineTableViewCell class],
  70. kFLEXMultilineDetailCell : [FLEXMultilineDetailTableViewCell class],
  71. kFLEXKeyValueCell : [FLEXKeyValueTableViewCell class],
  72. kFLEXCodeFontCell : [FLEXCodeFontCell class],
  73. }];
  74. }
  75. return self;
  76. }
  77. #pragma mark - Public
  78. - (void)registerCells:(NSDictionary<NSString*, Class> *)registrationMapping {
  79. [registrationMapping enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, Class cellClass, BOOL *stop) {
  80. [self registerClass:cellClass forCellReuseIdentifier:identifier];
  81. }];
  82. }
  83. @end