Latest 1.1.0
License MIT
Platforms ios 7.0, requires ARC

Simple Objective-C and Swift implementation for getting rid of your UITableView & UICollectionView delegate and data source code from your UIViewController and share it between UIViewControllers.


  • iOS 7.0 or newer


  • Install via cocoapods (just add pod 'ABDataSourceController', '~> 1.1' to your Podfile), or clone this repository and drag the content of ABDataSourceController/objc folder to your project.
  • For using with table view you just need to create your custom data source controller object that implements ABTableViewDataSourceController protocol:
#import "ABDataSourceController.h"

@interface CustomDataSourceController : NSObject <ABTableViewDataSourceController>

@property (nonatomic, assign) IBOutlet UITableView *tableView;
@property (nonatomic, assign) IBOutlet UIViewController *viewController;


@implementation CustomDataSourceController {
    NSArray *_dataSource;

@synthesize tableView = _tableView;
@synthesize viewController = _viewController;

  • Now override refreshDataSourceWithCompletionHandler method to load data source:
- (void)refreshDataSourceWithCompletionHandler:(void (^)())completion {
    [self loadDataSource];

    if (completion)
  • and write all your UITableViewDataSource & UITableViewDelegate code:
#pragma mark UITableViewDataSource Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"DefaultCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

    cell.textLabel.text = [_dataSource objectAtIndex:indexPath.row];

    return cell;
  • To use from Interface Builder add an object to your view controlle XIB and change it’s class to CustomDataSourceController (click here for tutorial). Now connect the tableView and viewController outlets for the newly created object and connect the table view’s dataSourceController outlet to your custom object. You’re ready to go!
  • To use from code initialize the data source controller in your UIViewController, assign it to your UITableView dataSourceController property and you’re ready to go!
#import "UITableView+DataSourceController.h"

@implementation MainViewController {
    IBOutlet UITableView *tableView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    // setup data source controller
    CustomDataSourceController *dataSourceCtrl = [[CustomDataSourceController alloc] init];
    dataSourceCtrl.tableView = tableView;
    dataSourceCtrl.viewController = self;
    tableView.dataSourceController = dataSourceCtrl;

    // load data source
    [tableView.dataSourceController refreshDataSourceWithCompletionHandler:nil];

  • For using with collection view follow the same principle described above and make sure your custom data source controller object conforms to ABCollectionViewDataSourceController protocol.


  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.


ABDataSourceController was created by Alex Bumbu.


ABDataSourceController is available under the MIT license. See the LICENSE file for more info.
For usage without attribution contact Alex Bumbu.

Latest podspec

    "name": "ABDataSourceController",
    "version": "1.1.0",
    "summary": "Simple to use approach to clean your UITableView data source & delegate code from your UIViewController and share it between controllers.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Alex Bumbu": ""
    "platforms": {
        "ios": "7.0"
    "source": {
        "git": "",
        "tag": "1.1.0"
    "source_files": "ABDataSourceController/**/*.{h,m}",
    "requires_arc": true

Pin It on Pinterest

Share This