Created
November 16, 2016 12:23
-
-
Save Frankacy/c9cb9f5612f79d5a366759559886f10e to your computer and use it in GitHub Desktop.
Table View Adapter
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
@interface TableViewAdapter : NSObject <FRKDataProvider, UITableViewDataSource> | |
- (instancetype)initWithDataProvider:(id<FRKDataProvider, FRKSectionInfoProvider>)provider | |
dataPresenter:(id<FRKTableViewDataPresenter>)presenter; | |
- (void)registerCellsForTableView:(UITableView *)tableView; | |
@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
@interface FRKTableViewAdapter () | |
@property(nonatomic, strong) id<FRKDataProvider, FRKSectionInfoProvider> provider; | |
@property(nonatomic, strong) id<FRKTableViewDataPresenter> presenter; | |
@end | |
@implementation FRKTableViewAdapter | |
- (instancetype)initWithDataProvider:(id<FRKDataProvider, FRKSectionInfoProvider>)provider | |
dataPresenter:(id<FRKTableViewDataPresenter>)presenter { | |
self = [super init]; | |
if (!self) { | |
return nil; | |
} | |
_provider = provider; | |
_presenter = presenter; | |
return self; | |
} | |
- (void)registerCellsForTableView:(UITableView *)tableView { | |
[self.presenter registerCellsForTableView:tableView]; | |
} | |
#pragma mark - FRKDataProvider | |
- (id)itemAtIndexPath:(NSIndexPath *)indexPath { | |
return [self.provider itemAtIndexPath:indexPath]; | |
} | |
- (NSIndexPath *)indexForItem:(id)item { | |
return [self.provider indexForItem:item]; | |
} | |
- (void)loadDataWithCompletion:(void(^)(NSError *error))completion { | |
[self.provider loadDataWithCompletion:completion]; | |
} | |
#pragma mark - UITableViewDataSource | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return [self.provider numberOfSections]; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return [self.provider numberOfItemsInSection:section]; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
id item = [self itemAtIndexPath:indexPath]; | |
return [self.presenter tableView:tableView cellForItem:item atIndexPath:indexPath]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment