123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // FLEXTableView.m
- // FLEX
- //
- // Created by Tanner on 4/17/19.
- // Copyright © 2020 FLEX Team. All rights reserved.
- //
- #import "FLEXTableView.h"
- #import "FLEXUtility.h"
- #import "FLEXSubtitleTableViewCell.h"
- #import "FLEXMultilineTableViewCell.h"
- #import "FLEXKeyValueTableViewCell.h"
- #import "FLEXCodeFontCell.h"
- FLEXTableViewCellReuseIdentifier const kFLEXDefaultCell = @"kFLEXDefaultCell";
- FLEXTableViewCellReuseIdentifier const kFLEXDetailCell = @"kFLEXDetailCell";
- FLEXTableViewCellReuseIdentifier const kFLEXMultilineCell = @"kFLEXMultilineCell";
- FLEXTableViewCellReuseIdentifier const kFLEXMultilineDetailCell = @"kFLEXMultilineDetailCell";
- FLEXTableViewCellReuseIdentifier const kFLEXKeyValueCell = @"kFLEXKeyValueCell";
- FLEXTableViewCellReuseIdentifier const kFLEXCodeFontCell = @"kFLEXCodeFontCell";
- #pragma mark Private
- @interface UITableView (Private)
- - (CGFloat)_heightForHeaderInSection:(NSInteger)section;
- - (NSString *)_titleForHeaderInSection:(NSInteger)section;
- @end
- @implementation FLEXTableView
- + (instancetype)flexDefaultTableView {
- #if FLEX_AT_LEAST_IOS13_SDK
- if (@available(iOS 13.0, *)) {
- #if !TARGET_OS_TV
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
- #else
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- #endif
- } else {
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- }
- #else
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- #endif
- }
- #pragma mark - Initialization
- + (id)groupedTableView {
- #if FLEX_AT_LEAST_IOS13_SDK
- if (@available(iOS 13.0, *)) {
- #if !TARGET_OS_TV
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
- #else
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- #endif
- } else {
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- }
- #else
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- #endif
- }
- + (id)plainTableView {
- return [[self alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- }
- + (id)style:(UITableViewStyle)style {
- return [[self alloc] initWithFrame:CGRectZero style:style];
- }
- - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
- self = [super initWithFrame:frame style:style];
- if (self) {
- [self registerCells:@{
- kFLEXDefaultCell : [FLEXTableViewCell class],
- kFLEXDetailCell : [FLEXSubtitleTableViewCell class],
- kFLEXMultilineCell : [FLEXMultilineTableViewCell class],
- kFLEXMultilineDetailCell : [FLEXMultilineDetailTableViewCell class],
- kFLEXKeyValueCell : [FLEXKeyValueTableViewCell class],
- kFLEXCodeFontCell : [FLEXCodeFontCell class],
- }];
- }
- return self;
- }
- #pragma mark - Public
- - (void)registerCells:(NSDictionary<NSString*, Class> *)registrationMapping {
- [registrationMapping enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, Class cellClass, BOOL *stop) {
- [self registerClass:cellClass forCellReuseIdentifier:identifier];
- }];
- }
- @end
|