Skip to content

Instantly share code, notes, and snippets.

@willard1218
Last active April 22, 2017 07:08
Show Gist options
  • Save willard1218/944080788aa355122cbb37ae7bb880c8 to your computer and use it in GitHub Desktop.
Save willard1218/944080788aa355122cbb37ae7bb880c8 to your computer and use it in GitHub Desktop.
Simplify register/dequeue TableViewCell
#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