*   >> lukeminen koulutus Artikkelit >> science >> programming

iPhone Core Data opetusohjelma Osa 3,2

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

Page   <<       [1] [2] [3] [4] [5] >>
Copyright © 2008 - 2016 lukeminen koulutus Artikkelit,https://koulutus.nmjjxx.com All rights reserved.