Skip to content

Instantly share code, notes, and snippets.

@buranmert
Created June 25, 2015 13:24
Show Gist options
  • Save buranmert/1e1c920d535eed624a1b to your computer and use it in GitHub Desktop.
Save buranmert/1e1c920d535eed624a1b to your computer and use it in GitHub Desktop.
A UITableViewController that has a UIView as its root view
//
// MBTableViewController.m
// MBTableViewController
//
// Created by Mert Buran on 20/06/2015.
// Copyright (c) 2015 Mert Buran. All rights reserved.
//
#import "MBTableViewController.h"
#import "CustomTableViewController.h" //just in case, you should use your own custom UITableViewController subclass
@interface MBTableViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) CustomTableViewController *childTableViewController;
@end
@implementation MBTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self addTableViewControllerToView];
}
- (void)addTableViewControllerToView {
[self.childTableViewController willMoveToParentViewController:self];
[self addChildViewController:self.childTableViewController];
[self.childTableViewController didMoveToParentViewController:self];
UIView *childView = self.childTableViewController.view;
[childView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view insertSubview:childView atIndex:0];
[childView coverSuperview]; //use your own autolayout wrapper method here
}
#pragma mark - Properties
- (CustomTableViewController *)childTableViewController {
if (_childTableViewController == nil) {
CustomTableViewController *tableViewController = [CustomTableViewController new];
tableViewController.tableView.dataSource = self;
tableViewController.tableView.delegate = self;
_childTableViewController = tableViewController;
}
return _childTableViewController;
}
#pragma mark - UITableViewDataSource methods
#warning mock implementation
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 60;
}
#warning mock implementation
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment