cell.detailTextLabel.text = recipes.recipeName;
break;
Bij 1:
cell.textLabel.text = @ "Bereidingstijd";
cell.detailTextLabel.text = recipes.cookingTime;
breken;
Standaard:
break;
}
return cel;
}
- (void) dealloc { waar het zegt
[recepten vrijlating];
[super dealloc];
}
end
Save beide bestanden en Open de RootViewController.
h en typ de volgende code:
interface RootViewController: UITableViewController {
NSFetchedResultsController * fetchedResultsController;
NSManagedObjectContext * managedObjectContext;
}
property (nonatomic, behouden) NSFetchedResultsController * fetchedResultsController;
property (nonatomic, behouden) NSManagedObjectContext * managedObjectContext;
end
In RootViewController.m, typt u dit in:
#import "RootViewController.h"
#import "AddRecipeViewController.h"
#import "Recipes.h"
#import "RecipeDetailViewController.
h"
implementation RootViewController
@ synthetiseren fetchedResultsController, managedObjectContext;
#pragma mark -
#pragma mark Bekijk levenscyclus
- (void) viewDidLoad {
[super viewDidLoad];
self.title = @ "Recepten";
self.navigationItem. leftBarButtonItem = self.editButtonItem;
UIBarButtonItem * addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd doel: zelf actie: @ selector (addRecipe)];
self.navigationItem.
rightBarButtonItem = addButton;
[addButton vrijlating];
NSError * error = nil;
als ([[zelf fetchedResultsController] performFetch: & error;]!) {
NSLog (@ "Onopgeloste fout% @,% @", fout, [fout UserInfo]);
af te breken ();
}
}
- (void) viewWillAppear: (BOOL) geanimeerde {
[super viewWillAppear: geanimeerde];
[self.
tableView reloadData];
}
#pragma mark -
#pragma mark een nieuw object
- (void) addRecipe {
AddRecipeViewController * addRecipeView = [[AddRecipeViewController alloc] initWithNibName: @ "AddRecipeViewController "bundel: [NSBundle mainBundle]];
Recepten * recepten = (Recipes *) [NSEntityDescription insertNewObjectForEntityForName: @" Recepten "inManagedObjectContext: self.managedObjectContext];
addRecipeView.recipes = recepten;
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: addRecipeView];
[self.
navigationController presentModalViewController: navController geanimeerd