Paina ⌘ - N. Luo uusi UIViewController kanssa XI B nimeltä AddIngredientViewController. Tuplaklikkaa IngredientsRootViewController.h ja kirjoita:
class Reseptit;
interface SelectFromIngredientsViewController: UITableViewController {
Reseptit * reseptit;
NSManagedObjectContext * managedObjectContext;
NSFetchedResultsController * fetchedResultsController;
}
property (nonatomic, säilyttää) Reseptit * reseptit;
property (nonatomic, säilyttää) NSManagedObjectContext * managedObjectContext;
property (nonatomic, säilyttää) NSFetchedResultsController * fetchedResultsController;
end
Avaa IngredientsRootViewController.
m ja kirjoita:
#import "IngredientsRootViewController.h"
#import "Ingredient.h"
#import "AddIngredientViewController.h"
#import "CoreDataTutorialPart2AppDelegate.h"
implementation IngredientsRootViewController
synthesize managedObjectContext, fetchedResultsController;
- (void) viewDidLoad {
[Super viewDidLoad];
UIBarButtonItem * addButton = [[ ,,,0],UIBarButtonItem Alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd tavoite: itse toiminta:selector (addIngredient)];
self.navigationItem.
leftBarButtonItem = addButton;
[addButton release];
//Poista kommentit seuraava rivi näyttää Muokkaa -painiketta navigointipalkin tämän View Controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
CoreDataTutorialPart2AppDelegate * appDelegate = (CoreDataTutorialPart2AppDelegate *) [ ,,,0],[UIApplication sharedApplication] edustaja];
self.managedObjectContext = appDelegate.
managedObjectContext;
NSError * error = nolla;
jos (! [[itse fetchedResultsController] performFetch: & virhe ;]) {
NSLog (@ "Ratkaisematon virhe% @,% @", virhe, [error UserInfo]);
keskeyttää ();
}
}
- (void) addIngredient {
AddIngredientViewController * addIngredientView = [[AddIngredientViewController alloc] initWithNibName: @ "AddIngredientViewController" kimppu: [NSBundle mainBundle]];
< p> Ainesosan * ainesosa = [NSEntityDescription insertNewObjectForEntityForName: @ "Ainesosalla" inManagedObjectContext: self.
managedObjectContext];
addIngredientView.ingredient = ainesosa;
UINavigationController * navController = [[UINavigationController alloc] initWithRootV
1 ja…