Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // In the .m file of your TTTableViewDataSource implementation
  2.  
  3. - (void)tableViewDidLoadModel:(UITableView*)tableView {
  4.     // the model has loaded, and hence Core Data entities are populated    
  5.     NSManagedObjectContext* context = appDelegate.managedObjectContext;
  6.    
  7.     NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
  8.     [fetchRequest setEntity:[NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:context]];
  9.     // set a batch size to control memory footprint
  10.     [fetchRequest setFetchBatchSize:25];
  11.    
  12.     NSSortDescriptor* nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
  13.     NSArray* sortDescriptors = [NSArray arrayWithObject:nameDescriptor];
  14.     [fetchRequest setSortDescriptors:sortDescriptors];
  15.    
  16.     _resultsController = [[MyNSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
  17.                                                              managedObjectContext:context
  18.                                                                sectionNameKeyPath:nil
  19.                                                                         cacheName:@"YourCacheName"];
  20.    
  21.     NSError* error;
  22.     if( ![_resultsController performFetch:&error] ) {
  23.         // handle error
  24.     }
  25.    
  26.     [nameDescriptor release];
  27.     [fetchRequest release];
  28. }
  29.  
  30. // override TTTableViewDataSource's method to return the cell TableItem we want - three20 will take care of returning the right cell
  31. - (id)tableView:(UITableView*)tableView objectForRowAtIndexPath:(NSIndexPath*)indexPath {
  32.    
  33.     DBResource* managedObject = (DBResource*)[_resultsController objectAtIndexPath:indexPath];
  34.    
  35.     TTTableItem* item = [TTTableItem itemWithText:managedObject.name
  36.                                               URL:@"tt://foo"]; // set the URL you need to
  37.    
  38.     return item;
  39. }