瀏覽代碼

Clean up cell reuse identifiers

Tanner Bennett 6 年之前
父節點
當前提交
8236fc97cc

+ 1 - 1
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -210,7 +210,7 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 - (UITableViewCell *)tableView:(__kindof UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 - (UITableViewCell *)tableView:(__kindof UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 {
     UITableViewCell *cell = [tableView
     UITableViewCell *cell = [tableView
-        dequeueReusableCellWithIdentifier:[tableView defaultReuseIdentifier]
+        dequeueReusableCellWithIdentifier:kFLEXDefaultCell
         forIndexPath:indexPath
         forIndexPath:indexPath
     ];
     ];
 
 

+ 3 - 2
Classes/Network/FLEXNetworkTransactionDetailTableViewController.m

@@ -16,6 +16,7 @@
 #import "FLEXMultilineTableViewCell.h"
 #import "FLEXMultilineTableViewCell.h"
 #import "FLEXUtility.h"
 #import "FLEXUtility.h"
 #import "FLEXManager+Private.h"
 #import "FLEXManager+Private.h"
+#import "FLEXTableView.h"
 
 
 typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
 typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
 
 
@@ -65,7 +66,7 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
 {
 {
     [super viewDidLoad];
     [super viewDidLoad];
 
 
-    [self.tableView registerClass:[FLEXMultilineTableViewCell class] forCellReuseIdentifier:kFLEXMultilineTableViewCellIdentifier];
+    [self.tableView registerClass:[FLEXMultilineTableViewCell class] forCellReuseIdentifier:kFLEXMultilineCell];
 }
 }
 
 
 - (void)setTransaction:(FLEXNetworkTransaction *)transaction
 - (void)setTransaction:(FLEXNetworkTransaction *)transaction
@@ -147,7 +148,7 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
 
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 {
-    FLEXMultilineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kFLEXMultilineTableViewCellIdentifier forIndexPath:indexPath];
+    FLEXMultilineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kFLEXMultilineCell forIndexPath:indexPath];
 
 
     FLEXNetworkDetailRow *rowModel = [self rowModelAtIndexPath:indexPath];
     FLEXNetworkDetailRow *rowModel = [self rowModelAtIndexPath:indexPath];
 
 

+ 4 - 0
Classes/ObjectExplorers/Controllers/FLEXObjectExplorerViewController.h

@@ -6,6 +6,10 @@
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //
 //
 
 
+#ifndef _FLEXObjectExplorerViewController_h
+#define _FLEXObjectExplorerViewController_h
+#endif
+
 #import "FLEXTableViewController.h"
 #import "FLEXTableViewController.h"
 
 
 typedef NS_ENUM(NSUInteger, FLEXObjectExplorerSection) {
 typedef NS_ENUM(NSUInteger, FLEXObjectExplorerSection) {

+ 1 - 1
Classes/ObjectExplorers/Controllers/FLEXObjectExplorerViewController.m

@@ -810,7 +810,7 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
 
 
     BOOL isCustomSection = explorerSection == FLEXObjectExplorerSectionCustom;
     BOOL isCustomSection = explorerSection == FLEXObjectExplorerSectionCustom;
     BOOL useDescriptionCell = explorerSection == FLEXObjectExplorerSectionDescription;
     BOOL useDescriptionCell = explorerSection == FLEXObjectExplorerSectionDescription;
-    NSString *cellIdentifier = useDescriptionCell ? kFLEXMultilineTableViewCellIdentifier : @"cell";
+    NSString *cellIdentifier = useDescriptionCell ? kFLEXMultilineCell : @"cell";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     if (!cell) {
     if (!cell) {
         if (useDescriptionCell) {
         if (useDescriptionCell) {

+ 4 - 0
Classes/ObjectExplorers/FLEXObjectExplorerFactory.h

@@ -8,7 +8,11 @@
 
 
 #import "FLEXGlobalsEntry.h"
 #import "FLEXGlobalsEntry.h"
 
 
+#ifndef _FLEXObjectExplorerViewController_h
+#import "FLEXObjectExplorerViewController.h"
+#else
 @class FLEXObjectExplorerViewController;
 @class FLEXObjectExplorerViewController;
+#endif
 
 
 @interface FLEXObjectExplorerFactory : NSObject <FLEXGlobalsEntry>
 @interface FLEXObjectExplorerFactory : NSObject <FLEXGlobalsEntry>
 
 

+ 6 - 2
Classes/ObjectExplorers/Views/FLEXMultilineTableViewCell.h

@@ -8,10 +8,14 @@
 
 
 #import "FLEXTableViewCell.h"
 #import "FLEXTableViewCell.h"
 
 
-extern NSString *const kFLEXMultilineTableViewCellIdentifier;
-
+/// A cell with both labels set to be multi-line capable.
 @interface FLEXMultilineTableViewCell : FLEXTableViewCell
 @interface FLEXMultilineTableViewCell : FLEXTableViewCell
 
 
 + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory;
 + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory;
 
 
 @end
 @end
+
+/// A \c FLEXMultilineTableViewCell initialized with \c UITableViewCellStyleSubtitle
+@interface FLEXMultilineDetailTableViewCell : FLEXMultilineTableViewCell
+
+@end

+ 10 - 2
Classes/ObjectExplorers/Views/FLEXMultilineTableViewCell.m

@@ -8,8 +8,6 @@
 
 
 #import "FLEXMultilineTableViewCell.h"
 #import "FLEXMultilineTableViewCell.h"
 
 
-NSString *const kFLEXMultilineTableViewCellIdentifier = @"kFLEXMultilineTableViewCellIdentifier";
-
 @implementation FLEXMultilineTableViewCell
 @implementation FLEXMultilineTableViewCell
 
 
 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
@@ -17,6 +15,7 @@ NSString *const kFLEXMultilineTableViewCellIdentifier = @"kFLEXMultilineTableVie
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
     if (self) {
         self.textLabel.numberOfLines = 0;
         self.textLabel.numberOfLines = 0;
+        self.detailTextLabel.numberOfLines = 0;
     }
     }
     return self;
     return self;
 }
 }
@@ -53,3 +52,12 @@ NSString *const kFLEXMultilineTableViewCellIdentifier = @"kFLEXMultilineTableVie
 }
 }
 
 
 @end
 @end
+
+@implementation FLEXMultilineDetailTableViewCell
+
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+    return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
+}
+
+@end

+ 1 - 4
Classes/ObjectExplorers/Views/FLEXSubtitleTableViewCell.h

@@ -8,10 +8,7 @@
 
 
 #import <UIKit/UIKit.h>
 #import <UIKit/UIKit.h>
 
 
-NS_ASSUME_NONNULL_BEGIN
-
+/// A cell initialized with \c UITableViewCellStyleSubtitle
 @interface FLEXSubtitleTableViewCell : UITableViewCell
 @interface FLEXSubtitleTableViewCell : UITableViewCell
 
 
 @end
 @end
-
-NS_ASSUME_NONNULL_END

+ 23 - 3
Classes/ObjectExplorers/Views/FLEXTableView.h

@@ -8,12 +8,32 @@
 
 
 #import <UIKit/UIKit.h>
 #import <UIKit/UIKit.h>
 
 
+#pragma mark Reuse identifiers
+
+typedef NSString * FLEXTableViewCellReuseIdentifier;
+
+/// A regular \c UITableViewCell initialized with \c UITableViewCellStyleDefault
+extern FLEXTableViewCellReuseIdentifier const kFLEXDefaultCell;
+/// A \c FLEXSubtitleTableViewCell initialized with \c UITableViewCellStyleSubtitle
+extern FLEXTableViewCellReuseIdentifier const kFLEXDetailCell;
+/// A \c FLEXMultilineTableViewCell initialized with \c UITableViewCellStyleDefault
+extern FLEXTableViewCellReuseIdentifier const kFLEXMultilineCell;
+/// A \c FLEXMultilineTableViewCell initialized with \c UITableViewCellStyleSubtitle
+extern FLEXTableViewCellReuseIdentifier const kFLEXMultilineDetailCell;
+
+#pragma mark - FLEXTableView
 @interface FLEXTableView : UITableView
 @interface FLEXTableView : UITableView
 
 
 + (instancetype)flexDefaultTableView;
 + (instancetype)flexDefaultTableView;
++ (instancetype)groupedTableView;
++ (instancetype)plainTableView;
 
 
-@property (nonatomic, readonly) NSString *defaultReuseIdentifier;
-@property (nonatomic, readonly) NSString *subtitleReuseIdentifier;
-@property (nonatomic, readonly) NSString *multilineReuseIdentifier;
+/// You do not need to register classes for any of the default reuse identifiers above
+/// (annotated as \c FLEXTableViewCellReuseIdentifier types) unless you wish to provide
+/// a custom cell for any of those reuse identifiers. By default, \c FLEXTableViewCell,
+/// \c FLEXSubtitleTableViewCell, and \c FLEXMultilineTableViewCell are used, respectively.
+///
+/// @param registrationMapping A map of reuse identifiers to \c UITableViewCell (sub)class objects.
+- (void)registerCells:(NSDictionary<NSString *, Class> *)registrationMapping;
 
 
 @end
 @end

+ 33 - 22
Classes/ObjectExplorers/Views/FLEXTableView.m

@@ -11,6 +11,13 @@
 #import "FLEXSubtitleTableViewCell.h"
 #import "FLEXSubtitleTableViewCell.h"
 #import "FLEXMultilineTableViewCell.h"
 #import "FLEXMultilineTableViewCell.h"
 
 
+FLEXTableViewCellReuseIdentifier const kFLEXDefaultCell = @"kFLEXDefaultCell";
+FLEXTableViewCellReuseIdentifier const kFLEXDetailCell = @"kFLEXDetailCell";
+FLEXTableViewCellReuseIdentifier const kFLEXMultilineCell = @"kFLEXMultilineCell";
+FLEXTableViewCellReuseIdentifier const kFLEXMultilineDetailCell = @"kFLEXMultilineDetailCell";
+
+#pragma mark Private
+
 @interface UITableView (Private)
 @interface UITableView (Private)
 - (CGFloat)_heightForHeaderInSection:(NSInteger)section;
 - (CGFloat)_heightForHeaderInSection:(NSInteger)section;
 - (NSString *)_titleForHeaderInSection:(NSInteger)section;
 - (NSString *)_titleForHeaderInSection:(NSInteger)section;
@@ -44,40 +51,44 @@
     return height;
     return height;
 }
 }
 
 
-- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
-{
+#pragma mark - Initialization
+
++ (id)groupedTableView {
+#if FLEX_AT_LEAST_IOS13_SDK
+    if (@available(iOS 13.0, *)) {
+        return [[self alloc] initWithFrame:CGRectZero style:UITableViewStyleInsetGrouped];
+    } 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)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
     self = [super initWithFrame:frame style:style];
     self = [super initWithFrame:frame style:style];
     if (self) {
     if (self) {
         [self registerCells:@{
         [self registerCells:@{
-            self.defaultReuseIdentifier : [FLEXTableViewCell class],
-            self.subtitleReuseIdentifier : [FLEXSubtitleTableViewCell class],
-            self.multilineReuseIdentifier : [FLEXMultilineTableViewCell class],
+            kFLEXDefaultCell : [FLEXTableViewCell class],
+            kFLEXDetailCell : [FLEXSubtitleTableViewCell class],
+            kFLEXMultilineCell : [FLEXMultilineTableViewCell class],
+            kFLEXMultilineDetailCell : [FLEXMultilineDetailTableViewCell class]
         }];
         }];
     }
     }
 
 
     return self;
     return self;
 }
 }
 
 
-- (void)registerCells:(NSDictionary<NSString*,Class> *)registrationMapping
-{
+#pragma mark - Public
+
+- (void)registerCells:(NSDictionary<NSString*, Class> *)registrationMapping {
     [registrationMapping enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, Class cellClass, BOOL *stop) {
     [registrationMapping enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, Class cellClass, BOOL *stop) {
         [self registerClass:cellClass forCellReuseIdentifier:identifier];
         [self registerClass:cellClass forCellReuseIdentifier:identifier];
     }];
     }];
 }
 }
 
 
-- (NSString *)defaultReuseIdentifier
-{
-    return @"kFLEXTableViewCellIdentifier";
-}
-
-- (NSString *)subtitleReuseIdentifier
-{
-    return @"kFLEXSubtitleTableViewCellIdentifier";
-}
-
-- (NSString *)multilineReuseIdentifier
-{
-    return kFLEXMultilineTableViewCellIdentifier;
-}
-
 @end
 @end