Latest 1.2.0
License MIT
Platforms ios 5.0, requires ARC
Frameworks CoreData, UIKit


GTTableViewController is a light weight subclass of UIViewController that integrates NSFetchedResultsController and UITableView to display data of CoreData.
It has a good scalability, and can be integrated to your project either by inheritance or as a child viewController using datasource methods.
To display the data in UITableView, all you need to do is to customize your own NSFetchRequest and UITableViewCell objects.

How to get started?


Write a GTTableViewController subclass and override its methods like this:


Return NSManagedObjectContext object which CoreData context you want to use. Default returns from AppDelegate, If you do not override it.

- (NSManagedObjectContext *)managedObjectContext
    id appDelegate = [UIApplication sharedApplication].delegate;
    return [appDelegate managedObjectContext];


Retrun NSFetchRequest object include the fetch rules and orders. This method must be overrided.

- (NSFetchRequest *)fetchRequest
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *playerEntity = [NSEntityDescription entityForName:@"Player" inManagedObjectContext:[self managedObjectContext]];
    [fetchRequest setEntity:playerEntity];

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"age" ascending:YES];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

    return fetchRequest;

UITableViewCell Display

Config your own UITableViewCell. Cell is empty, if you do not override it.

- (void)configCell:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController
    Player *player = [fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text =;


Return your own UITableViewCell. Cell is UITableViewCellStyleDefault, if you do not override it.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    [self configCell:cell cellForRowAtIndexPath:indexPath fetchedResultsController:fetchedResultsController];

    return cell;


DataSource is almost like Inheritance way. This way is used for integrating it as a subview or a child viewController.


In UIViewController object, write code like:

GTTableViewController *viewController = [[GTTableViewController alloc] init];
viewController.dataSource = self;
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];


- (NSManagedObjectContext *)managedObjectContextGTTableViewController:(GTTableViewController *)viewController


This method is requeired.

- (NSFetchRequest *)fetchRequestGTTableViewController:(GTTableViewController *)viewController

UITableViewCell Display

- (void)configCell:(UITableViewCell *)cell viewController:(GTTableViewController *)viewController fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController


- (void)configCell:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath viewController:(GTTableViewController *)viewController fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController

Other useful infomation

Fetch objects method

- (void)performFetch

This property controls the max number of displayed fetched objects in UITableView.

@property (nonatomic, assign) int numberOfFetchLimit


龚涛 Gong Tao mail: [email protected]

Latest podspec

    "name": "GTTableViewController",
    "version": "1.2.0",
    "summary": "CoreData Display in CoreData",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "gongtao": "[email protected]"
    "platforms": {
        "ios": "5.0"
    "source": {
        "git": "",
        "commit": "0b81ca00ed9678a2c9fef1de80c1eb89f62d6362",
        "tag": "1.2.0"
    "source_files": "Class/*.{h,m}",
    "frameworks": [
    "requires_arc": true

Pin It on Pinterest

Share This