// In the .m file of your TTTableViewDataSource implementation
- (void)tableViewDidLoadModel:(UITableView*)tableView {
// the model has loaded, and hence Core Data entities are populated
NSManagedObjectContext* context = appDelegate.managedObjectContext;
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]];
// set a batch size to control memory footprint
[fetchRequest setFetchBatchSize:25];
NSSortDescriptor* nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray* sortDescriptors = [NSArray arrayWithObject:nameDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
_resultsController = [[MyNSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:@"YourCacheName"];
NSError* error;
if( ![_resultsController performFetch:&error] ) {
// handle error
}
[nameDescriptor release];
[fetchRequest release];
}
// override TTTableViewDataSource's method to return the cell TableItem we want - three20 will take care of returning the right cell
- (id)tableView:(UITableView*)tableView objectForRowAtIndexPath:(NSIndexPath*)indexPath {
DBResource* managedObject = (DBResource*)[_resultsController objectAtIndexPath:indexPath];
TTTableItem* item = [TTTableItem itemWithText:managedObject.name
URL:@"tt://foo"]; // set the URL you need to
return item;
}