Prima ⌘ - N. Criar um novo UIViewController com um AddIngredientViewController XIB nomeado. Clique duas vezes em IngredientsRootViewController.h e digite:
class Receitas;
interface SelectFromIngredientsViewController: UITableViewController {
Receitas * receitas;
NSManagedObjectContext * managedObjectContext;
NSFetchedResultsController * fetchedResultsController;
}
property (não-atômicas, conservem) Receitas * receitas;
property (nonatomic, reter) NSManagedObjectContext * managedObjectContext;
property (nonatomic, reter) NSFetchedResultsController * fetchedResultsController;
end
Open IngredientsRootViewController.
m e digite:
#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: alvo UIBarButtonSystemItemAdd: auto ação:selector (addIngredient)];
self.navigationItem.
leftBarButtonItem = addButton;
[liberação addButton];
//Uncomment a seguinte linha para exibir um botão Editar na barra de navegação para este controlador de vista
self.navigationItem.rightBarButtonItem = self.editButtonItem;.
CoreDataTutorialPart2AppDelegate * appDelegate = (CoreDataTutorialPart2AppDelegate *) [ ,,,0],[UIApplication sharedApplication] delegado];
self.managedObjectContext = appDelegate.
managedObjectContext;
NSError * error = nil;
if ([[auto fetchedResultsController] performFetch: & erro ;]) {
NSLog (@ "erro não resolvido% @,% @", erro, [erro userInfo]);
abort ();
}
}
- (void) {addIngredient
AddIngredientViewController * addIngredientView = [[AddIngredientViewController alloc] initWithNibName: @ pacote "AddIngredientViewController": [NSBundle mainBundle]];
< p> Ingrediente * ingrediente = [NSEntityDescription insertNewObjectForEntityForName: @ "ingrediente" inManagedObjectContext: self.
managedObjectContext];
addIngredientView.ingredient = ingrediente;
UINavigationController * NavController = [[UINavigationController Alloc] initWithRootV
net de Controle do Usuário