Created
November 18, 2015 16:21
-
-
Save rogerluan/7947942b724780995089 to your computer and use it in GitHub Desktop.
Code snippet for blog series.
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
//TableDataSource.h | |
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
@interface TableDataSource : NSObject<UITableViewDataSource> | |
@property (nonatomic, strong) NSArray *data; | |
@end | |
//TableDataSource.m | |
#import "TableDataSource.h" | |
#import "CustomTableViewCell.h" | |
@implementation TableDataSource | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return (self.data == nil ? 0 : 1); | |
} | |
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return self.data.count; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CustomTableViewCell class]) forIndexPath:indexPath]; | |
return cell; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment