Last active
April 22, 2017 07:08
-
-
Save willard1218/944080788aa355122cbb37ae7bb880c8 to your computer and use it in GitHub Desktop.
Simplify register/dequeue TableViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UITableView (Helper) | |
- (void)registerClass:(_Nonnull Class)cellClass; | |
- (void)registerClassList:(NSArray <Class> *_Nonnull)cellClassList; | |
- (__kindof UITableViewCell *_Nonnull)dequeueReusableCellWithClass:(_Nonnull Class)cellClass forIndexPath:(NSIndexPath *_Nonnull)indexPath; | |
@end | |
@implementation UITableView (Helper) | |
- (void)registerClass:(_Nonnull Class)cellClass { | |
NSString *reuseIdentifier = NSStringFromClass(cellClass); | |
[self registerClass:cellClass forCellReuseIdentifier:reuseIdentifier]; | |
} | |
- (void)registerClassList:(NSArray <Class>*)cellClassList { | |
for (Class class in cellClassList) { | |
[self registerClass:class]; | |
} | |
} | |
- (__kindof UITableViewCell *_Nonnull)dequeueReusableCellWithClass:(_Nonnull Class)cellClass forIndexPath:(NSIndexPath *_Nonnull)indexPath { | |
return [self dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass) forIndexPath:indexPath]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment