Created
November 8, 2018 11:07
-
-
Save matax87/46195ed4dd6ff948ccf1db533f57b7ab to your computer and use it in GitHub Desktop.
Customize UITableViewController table view class
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
// | |
// MTXTableViewController.h | |
// InBankMobile | |
// | |
// Created by Matteo Matassoni on 08/11/2018. | |
// Copyright © 2018 Matteo Matassoni. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface MTXTableViewController : UITableViewController | |
#if UIKIT_DEFINE_AS_PROPERTIES | |
@property (class, nonatomic, readonly) Class tableViewClass; // override this method to provide a custom class of UITableView | |
#else | |
+ (Class)tableViewClass; // override this method to provide a custom class of UITableView | |
#endif | |
@end | |
NS_ASSUME_NONNULL_END |
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
// | |
// MTXTableViewController.m | |
// InBankMobile | |
// | |
// Created by Matteo Matassoni on 08/11/2018. | |
// Copyright © 2018 Matteo Matassoni. All rights reserved. | |
// | |
#import "MTXTableViewController.h" | |
@interface MTXTableViewController () | |
@property (nonatomic) UITableViewStyle style; | |
@end | |
@implementation MTXTableViewController | |
- (instancetype)initWithStyle:(UITableViewStyle)style { | |
self = [super initWithStyle:style]; | |
if (!self) { | |
return nil; | |
} | |
_style = style; | |
return self; | |
} | |
+ (Class)tableViewClass { | |
return [UITableView class]; | |
} | |
- (void)loadView { | |
Class desiredTVClass = [[self class] tableViewClass]; | |
if (self.nibName) { | |
[super loadView]; | |
// Just for completeness. | |
self.style = self.tableView.style; | |
NSAssert([self.tableView isKindOfClass:desiredTVClass], @"%@ must be a an instance of %@ (or subclass)", self.tableView, NSStringFromClass(desiredTVClass)); | |
} else { | |
UITableView *tableView = [[desiredTVClass alloc] initWithFrame:CGRectZero style:self.style]; | |
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
self.tableView = tableView; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment