celle = [[[UITableViewCell Alloc] initWithStyle: UITableViewCellStyleValue2 reuseIdentifier: CellIdentifier] autorelease]
}
kontakten (indexPath.row) {
tilfælde 0:
cell.textLabel.text = @ "Navn",
cell.detailTextLabel.text = recipes.recipeName;
break;
tilfælde 1:
cell.textLabel.text = @ "Tilberedningstid"
cell.detailTextLabel.text = recipes.
cookingTime;
break;
Standard:
break;
}
tilbagevenden celle;
}
- (void) dealloc { Hvor der står
[opskrifter frigivelse]
[super dealloc]
}
end
Gem begge filer og åbne RootViewController.h og indtast følgende kode:
interface RootViewController: UITableViewController {
NSFetchedResultsController * fetchedResultsController;
NSManagedObjectContext * managedObjectContext;
}
property (nonatomic, beholde) NSFetchedResultsController * fetchedResultsController;
property (nonatomic, beholde) NSManagedObjectContext * managedObjectContext;
end
RootViewController.
m, skriver dette på:
#import "RootViewController.h"
#import "AddRecipeViewController.h"
#import "Recipes.h"
#import "RecipeDetailViewController.h"
implementation RootViewController
synthesize fetchedResultsController, managedObjectContext;
#pragma mark -
#pragma mark Vis livscyklus
- (void) viewDidLoad {
[super viewDidLoad]
self.title = @ "Opskrifter"
self.navigationItem. leftBarButtonItem = self.
editButtonItem;
UIBarButtonItem * addButton = [[UIBarButtonItem Alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd mål: self handling:selector (addRecipe)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton frigivelse]
NSError * fejl = intet;
if ([[selv fetchedResultsController] performFetch: & fejl;]!) {
NSLog (@ "Uløste fejl% @,% @", fejl, [fejl UserInfo]),
abort ();
}
}
- (void) viewWillAppear: (BOOL) animated {
[super viewWillAppear: animerede]
[self.
tableView reloadData]
}
#pragma mark -
#pragma mark Tilføj et nyt objekt
- (void) addRecipe {
AddRecipeViewController * addRecipeView = [[AddRecipeViewController Alloc] initWithNibName: @ "AddRecipeViewContro