*   >> Lectura Educación Artículos >> science >> programación

iPhone Core Data Tutorial Parte 3,2

Pulse ⌘ - N. Crear un nuevo UIViewController con un AddIngredientViewController XIB nombrado. Doble click en IngredientsRootViewController.h y escriba:

class Recetas;

interface SelectFromIngredientsViewController: UITableViewController {

Recetas * recetas;

NSManagedObjectContext * managedObjectContext;

NSFetchedResultsController * fetchedResultsController;

}

property (retener no atómicas,) * Recetas recetas;

property (no atómica, retener) NSManagedObjectContext * managedObjectContext;

property (no atómica, retener) NSFetchedResultsController * fetchedResultsController;

end

Abrir IngredientsRootViewController.

m y escribe:

import "IngredientsRootViewController.h"

import

"Ingredient.h"

import

"AddIngredientViewController.h"

import "CoreDataTutorialPart2AppDelegate.h"

implementation IngredientsRootViewController

synthesize managedObjectContext, fetchedResultsController;

- (void) {viewDidLoad

[súper viewDidLoad];

UIBarButtonItem * addButton = [[ ,,,0],UIBarButtonItem alloc] initWithBarButtonSystemItem: objetivo UIBarButtonSystemItemAdd: auto acción:selector (addIngredient)];

self.navigationItem.

leftBarButtonItem = addButton;

[liberación addButton];

//Elimine la siguiente línea para mostrar un botón Editar en la barra de navegación para este controlador de vista

self.navigationItem.rightBarButtonItem = self.editButtonItem;.

CoreDataTutorialPart2AppDelegate * AppDelegate = (CoreDataTutorialPart2AppDelegate *) [ ,,,0],[UIApplication sharedApplication] delegada];

self.managedObjectContext = appDelegate.

managedObjectContext;

NSError * Error = nil;

si ([[auto fetchedResultsController] performFetch: y error ;]) {

NSLog (@ "error sin resolver% @,% @", error, [error userInfo]);

abortar ();

}

}

- (void) {addIngredient

AddIngredientViewController * addIngredientView = [[AddIngredientViewController alloc] initWithNibName: @ paquete "AddIngredientViewController": [NSBundle mainBundle]];

< p> Ingrediente * ingrediente = [NSEntityDescription insertNewObjectForEntityForName: @ "ingrediente" inManagedObjectContext: self.

managedObjectContext];

addIngredientView.ingredient = ingrediente;

UINavigationController * NavController = [[Alloc UINavigationController] in

Page   <<       [1] [2] [3] [4] [5] >>
Copyright © 2008 - 2016 Lectura Educación Artículos,https://lectura.nmjjxx.com All rights reserved.