Skip to content

Instantly share code, notes, and snippets.

@rogerluan
Created November 18, 2015 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerluan/7947942b724780995089 to your computer and use it in GitHub Desktop.
Save rogerluan/7947942b724780995089 to your computer and use it in GitHub Desktop.
Code snippet for blog series.
//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