*   >> Lezen Onderwijs artikelen >> science >> programming

iPhone Core Data Tutorial Part 2

eForKey: @ "recipeImage"];

}

- (void) didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

}

- (void) viewDidUnload {

}

- (void) dealloc {

[superdealloc];

[recepten versie];

[imageView vrijlating];

}

end

deze opslaan en openen AddRecipeViewController.h en voeg een UIButton genaamd photoButton en een IBAction methode wanneer de knop wordt geklikt

interface AddRecipeViewController.

UIViewController {

Recepten * recepten;

UITextField * textFieldOne;

UITextField * textFieldTwo;

UIButton * photoButton;

}

property (nonatomic, behouden) Recepten * recepten;

property (nonatomic, behouden) IBOutletUITextField * textFieldOne;

property (nonatomic, behouden) IBOutletUITextField * textFieldTwo;

property (nonatomic, behouden) IBOutletUIButton * photoButton;

- (IBAction) photoButtonPressed;

< p>end

Open het .m-bestand en schrijven:

#import "AddRecipeViewController.h"

#import "Recipes.h"

#import "PhotoViewController.

h"

implementation AddRecipeViewController

@ synthetiseren recepten, textFieldOne, textFieldTwo, photoButton;

- (void) viewDidLoad {

[superviewDidLoad];

self.title = @ "Recept toevoegen";

UIBarButtonItem * cancelButton = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCanceltarget:selfaction:@selector(cancel)];

self.navigationItem.

leftBarButtonItem = CancelButton;

[cancelButton vrijlating];

UIBarButtonItem * saveButton = [[UIBarButtonItemalloc] initWithTitle:@"Save"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(save)];

self.navigationItem.rightBarButtonItem = SaveButton;

[saveButton vrijlating];

[photoButtonsetImage: recipes.recipeThumbnailImage forState: UIControlStateNormal];

}

- (void) viewWillAppear: (BOOL) geanimeerde {

[superviewWillAppear: geanimeerde];

[photoButtonsetImage: recipes.

recipeThumbnailImage forState: UIControlStateNormal];

}

- (void ) annuleren {

[recipes.managedObjectContextdeleteObject: recepten];

NSError * error = nil;

als ([recipes.managedObjectContextsave: & error]!) {

//Handle fout

NSLog (@ "Onopgeloste fout% @,% @", fout, [fout UserInfo]);

exit (-1); //Fail

}

[selfdismissModalViewControllerAnimated: JA];

}

- (void) sparen {

recipes.recipeName = textFieldOne.text;

recipes.cookingTime = textFieldTwo.text;

NSError * error = nil;

als ([recipes.

managedObjectContex

Page   <<  [1] [2] [3] [4] [5] [6] [7] [8] [9] >>
Copyright © 2008 - 2016 Lezen Onderwijs artikelen,https://onderwijs.nmjjxx.com All rights reserved.