рдкрд╛рд░реНрд╕рд┐рдВрдЧ iPhone рдХреЛрд░ рдбреЗрдЯрд╛ рд╡реНрдпрдВрдЬрдиреЛрдВред рднрд╛рдЧ реи

рдкрд░рд┐рдЪрдп


рдпрд╣ рд▓реЗрдЦ, рд╢реНрд░реГрдВрдЦрд▓рд╛ рдореЗрдВ рджреВрд╕рд░рд╛ рдФрд░ рдЕрдВрддрд┐рдо рд▓реЗрдЦ "рдкрд╛рд░реНрд╕рд┐рдВрдЧ iPhone рдХреЛрд░ рдбреЗрдЯрд╛ рд╡реНрдпрдВрдЬрдиреЛрдВред" рдЖрдк рд▓реЗрдЦ рдХрд╛ рдкрд╣рд▓рд╛ рднрд╛рдЧ рдпрд╣рд╛рдВ рдкрдврд╝ рд╕рдХрддреЗ рд╣реИрдВред рд╢реНрд░реГрдВрдЦрд▓рд╛ рдХрд╛ рд▓рдХреНрд╖реНрдп рдПрдХ рдиреМрд╕рд┐рдЦрд┐рдпрд╛ iOS рдбреЗрд╡рд▓рдкрд░ рдХреЛ рдпрд╣ рд╕рдордЭрдиреЗ рдореЗрдВ рдорджрдж рдХрд░рдирд╛ рд╣реИ рдХрд┐ рдХреЛрд░ рдбреЗрдЯрд╛ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░ SQLite рдбреЗрдЯрд╛рдмреЗрд╕ рдХреЗ рд╕рд╛рде iPhone рдХреЛрд░ рдбреЗрдЯрд╛ рд╡реНрдпрдВрдЬрдиреЛрдВ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдПрдХ рдЙрджрд╛рд╣рд░рдг рдХреЗ рд░реВрдк рдореЗрдВ рд╕рд╣реА рдврдВрдЧ рд╕реЗ рдХреИрд╕реЗ рдХрд╛рдо рдХрд┐рдпрд╛ рдЬрд╛рдПред рдЕрдВрддрд┐рдо рд▓реЗрдЦ рдореЗрдВ, рд╣рдо рдбреЗрдЯрд╛рдмреЗрд╕ рд╕реЗ рд░рд┐рдХреЙрд░реНрдб рдЬреЛрдбрд╝рдиреЗ, рд╕рдВрдкрд╛рджрд┐рдд рдХрд░рдиреЗ рдФрд░ рд╣рдЯрд╛рдиреЗ рдХреА рдХрд╛рд░реНрдпрдХреНрд╖рдорддрд╛ рдкрд░ рд╡рд┐рдЪрд╛рд░ рдХрд░реЗрдВрдЧреЗред

рдЖрд╡рд╢реНрдпрдХ рд╢рд░реНрддреЗрдВ


рдЗрд╕ рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдХреЗ рд╕реНрд░реЛрдд рдХреЛрдб рдХреЗ рд╕реНрд╡рддрдВрддреНрд░ рдЕрдзреНрдпрдпрди рдХреЗ рд▓рд┐рдП, рдЖрдкрдХреЛ рдЙрдкрдХрд░рдгреЛрдВ рдХреЗ рдПрдХ рдорд╛рдирдХ рд╕реЗрдЯ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ:

рдпрд╣ рд╕реЗрдЯ рдЖрдкрдХреЛ рд╕рд┐рдореНрдпреБрд▓реЗрдЯрд░ рдкрд░ рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдХреЛ рджреЗрдЦрдиреЗ, рд╕рдВрд╢реЛрдзрд┐рдд рдХрд░рдиреЗ рдФрд░ рдЪрд▓рд╛рдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рджреЗрдЧрд╛ред рдпрджрд┐ рдЖрдк рдЗрд╕реЗ рд╡рд╛рд╕реНрддрд╡рд┐рдХ iPhone рдкрд░ рдЪрд▓рд╛рдиреЗ рдХрд╛ рдкреНрд░рдпрд╛рд╕ рдХрд░рдирд╛ рдЪрд╛рд╣рддреЗ рд╣реИрдВ, рддреЛ iOS рдбреЗрд╡рд▓рдкрд░ рдкреНрд░реЛрдЧреНрд░рд╛рдо рдореЗрдВ рднрд╛рдЧреАрджрд╛рд░реА рдЖрд╡рд╢реНрдпрдХ рд╣реИред

рдФрд░ рдЗрд╕рдХреЗ рдЕрд▓рд╛рд╡рд╛, рдорд╣рддреНрд╡рдкреВрд░реНрдг рд░реВрдк рд╕реЗ, рдЖрдкрдХреЛ рдСрдмреНрдЬреЗрдХреНрдЯ-рд╕реА рднрд╛рд╖рд╛ рдФрд░ рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдХреА рд╕рдВрд░рдЪрдирд╛ рдХреА рдПрдХ рдмреБрдирд┐рдпрд╛рджреА рд╕рдордЭ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред

рдЙрдкрдпреЛрдЧ рдХреА рдЧрдИ рд╕рд╛рдордЧреНрд░рд┐рдпреЛрдВ рдФрд░ рдЙрдкрдХрд░рдгреЛрдВ рдХреЗ рд▓рд┐рдВрдХ рд╕рдиреНрджрд░реНрдн рдЕрдиреБрднрд╛рдЧ рдореЗрдВ рджрд┐рдП рдЧрдП рд╣реИрдВред

рдХреИрд╕реЗ рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП


рддреЛ, рдкрд╣рд▓реА рдЪреАрдЬ рдЬреЛ рд╣рдореЗрдВ рдЪрд╛рд╣рд┐рдП рд╡рд╣ рд╣реИ рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ред рдЗрд╕ рдкреНрд░реЛрдЬреЗрдХреНрдЯ рдореЗрдВ рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╡реНрдпреВ рдХрдВрдЯреНрд░реЛрд▓рд░ - RecipeAddViewController рдЬрд┐рдореНрдореЗрджрд╛рд░ рд╣реИред рдЗрд╕рдХреА рд╕рд╛рдордЧреНрд░реА рдкрд░ рд╡рд┐рдЪрд╛рд░ рдХрд░реЗрдВред

RecipeAddViewController.h
@protocol RecipeAddDelegate; @class Recipe; @interface RecipeAddViewController : UIViewController <UITextFieldDelegate> { @private // Recipe,   managedObjectContext Recipe *recipe; //     UITextField *nameTextField; id <RecipeAddDelegate> delegate; } @property(nonatomic, retain) Recipe *recipe; @property(nonatomic, retain) IBOutlet UITextField *nameTextField; @property(nonatomic, assign) id <RecipeAddDelegate> delegate; //   - (void)save; //    - (void)cancel; @end @protocol RecipeAddDelegate <NSObject> // recipe == nil on cancel - (void)recipeAddViewController:(RecipeAddViewController *)recipeAddViewController didAddRecipe:(Recipe *)recipe; @end 

RecipeAddViewController.m
 #import "RecipeAddViewController.h" #import "Recipe.h" @implementation RecipeAddViewController @synthesize recipe; @synthesize nameTextField; @synthesize delegate; - (void)viewDidLoad { //  navigation bar self.navigationItem.title = @"Add Recipe"; //  Cancel      cancel UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)]; self.navigationItem.leftBarButtonItem = cancelButtonItem; [cancelButtonItem release]; //  Save      save UIBarButtonItem *saveButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(save)]; self.navigationItem.rightBarButtonItem = saveButtonItem; [saveButtonItem release]; [nameTextField becomeFirstResponder]; } ... //   - (void)save { recipe.name = nameTextField.text; NSError *error = nil; if (![recipe.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } [self.delegate recipeAddViewController:self didAddRecipe:recipe]; } //    - (void)cancel { [recipe.managedObjectContext deleteObject:recipe]; NSError *error = nil; if (![recipe.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } [self.delegate recipeAddViewController:self didAddRecipe:nil]; } //..    ARC,    - (void)dealloc { [recipe release]; [nameTextField release]; [super dealloc]; } @end 

рдирддреАрдЬрддрди, рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдЬреЛрдбрд╝рдиреЗ рдХреЗ рд▓рд┐рдП рдлреЙрд░реНрдо рдирд┐рдореНрдирд╛рдиреБрд╕рд╛рд░ рд╣реИ

рд╕рд╣реЗрдЬрдиреЗ рдФрд░ рд░рджреНрдж рдХрд░рдиреЗ рдХреА рд╡рд┐рд╕реНрддреГрдд рдЪрд░реНрдЪрд╛ рдиреАрдЪреЗ рджреА рдЬрд╛рдПрдЧреАред

рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдлреЙрд░реНрдо рдЦреЛрд▓реЗрдВ


рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдмрдирд╛рдиреЗ рдХрд╛ рдмрдЯрди рд╣рдорд╛рд░реЗ рдЖрд╡реЗрджрди рдХреА рдореБрдЦреНрдп рд╡рд┐рдВрдбреЛ рдореЗрдВ рд╕реНрдерд┐рдд рд╣реИ (рдКрдкрд░ рд╕реНрдХреНрд░реАрдирд╢реЙрдЯ рджреЗрдЦреЗрдВ)ред рдЗрд╕реЗ рдФрд░ рдЕрдзрд┐рдХ рдЬрд╛рдирдмреВрдЭрдХрд░ рд╡рд┐рдЪрд╛рд░ рдХрд░реЗрдВред

рдпрд╣ рдмрдЯрди RecipeListTableViewController рдХрдВрдЯреНрд░реЛрд▓рд░ рдХреЗ рд╡реНрдпреВрдбреАрдбрд▓рдб рд╡рд┐рдзрд┐ рдореЗрдВ рдмрдирд╛рдпрд╛ рдЧрдпрд╛ рд╣реИред
 UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)]; self.navigationItem.rightBarButtonItem = addButtonItem; [addButtonItem release]; 

рдЗрд╕ рдмрдЯрди рдХреЗ рд╕рд╛рде рдРрдб рдПрдХреНрд╢рди рдЬреБрдбрд╝рд╛ рд╣реБрдЖ рд╣реИ, рдЬреЛ рдХрд┐ RecipeListTableViewController рдХрдВрдЯреНрд░реЛрд▓рд░ (рд╕реЛрд░реНрд╕ рдХреЛрдб рдореЗрдВ рдЯрд┐рдкреНрдкрдгрд┐рдпрд╛рдВ рджреЗрдЦреЗрдВ) рдореЗрдВ рднреА рд╕реНрдерд┐рдд рд╣реИред
 - (void)add:(id)sender { //  RecipeAddViewController     RecipeAddViewController *addController = [[RecipeAddViewController alloc] initWithNibName:@"RecipeAddView" bundle:nil]; //   RecipeListTableViewController addController.delegate = self; // managedObjectContext   Recipe   NSEntityDescription,   -      Recipe Recipe *newRecipe = [NSEntityDescription insertNewObjectForEntityForName:@"Recipe" inManagedObjectContext:self.managedObjectContext]; //   Recipe  RecipeAddViewController addController.recipe = newRecipe; //   RecipeAddViewController UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController]; [self presentModalViewController:navigationController animated:YES]; [navigationController release]; [addController release]; } 

рдЗрд╕ рдХреНрд░рд┐рдпрд╛ рдХреЛ рдХрд░рдиреЗ рдХреЗ рдмрд╛рдж, рдКрдкрд░ рд╡рд░реНрдгрд┐рдд рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рдЬреЛрдбрд╝рдиреЗ рдХрд╛ рдлреЙрд░реНрдо рдЦреБрд▓ рдЬрд╛рдПрдЧрд╛ред рдЗрд╕ рдлрд╝реЙрд░реНрдо рдкрд░, рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдХреЗ рд▓рд┐рдП рджреЛ рдХреНрд░рд┐рдпрд╛рдПрдВ рдЙрдкрд▓рдмреНрдз рд╣реИрдВ - рд╕рд╣реЗрдЬреЗрдВ рдФрд░ рд░рджреНрдж рдХрд░реЗрдВред

рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рд╕рд╣реЗрдЬреЗрдВред

 - (void)save { // name  Recipe     recipe.name = nameTextField.text; NSError *error = nil; //   if (![recipe.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } //     RecipeDetailViewController (     .    "  ") [self.delegate recipeAddViewController:self didAddRecipe:recipe]; } 

рдПрдХ рдирдпрд╛ рдиреБрд╕реНрдЦрд╛ рд╕рд╣реЗрдЬрдирд╛ рд░рджреНрдж рдХрд░реЗрдВ

 - (void)cancel { //    Recipe,  ,        [recipe.managedObjectContext deleteObject:recipe]; NSError *error = nil; if (![recipe.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } //   [self.delegate recipeAddViewController:self didAddRecipe:nil]; } 

рдкреНрд░рджрд░реНрд╢рд┐рдд рдиреБрд╕реНрдЦрд╛

 - (void)recipeAddViewController:(RecipeAddViewController *)recipeAddViewController didAddRecipe:(Recipe *)recipe { if (recipe) { //   Recipe   nil -    [self showRecipe:recipe animated:NO]; } [self dismissModalViewControllerAnimated:YES]; } - (void)showRecipe:(Recipe *)recipe animated:(BOOL)animated { //        ,       RecipeDetailViewController *detailViewController = [[RecipeDetailViewController alloc] initWithStyle:UITableViewStyleGrouped]; detailViewController.recipe = recipe; [self.navigationController pushViewController:detailViewController animated:animated]; [detailViewController release]; } 

рдХреИрд╕реЗ рдПрдХ рдирдпрд╛ рд╕рдВрдШрдЯрдХ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП



рдЬреИрд╕рд╛ рдХрд┐ рдЖрдк рдКрдкрд░ рджрд┐рдП рдЧрдП рд╕реНрдХреНрд░реАрдирд╢реЙрдЯ рдореЗрдВ рджреЗрдЦ рд╕рдХрддреЗ рд╣реИрдВ, рдЬрдм рдиреБрд╕реНрдЦрд╛ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рд╡рд┐рд╕реНрддреГрдд рдЬрд╛рдирдХрд╛рд░реА, рд╕рдВрдкрд╛рджрди рдореЛрдб рдореЗрдВ, рд▓рд┐рдВрдХ "рдШрдЯрдХ рдЬреЛрдбрд╝реЗрдВ" рдЙрдкрд▓рдмреНрдз рд╣реИред рдпрд╣ рд╡рд┐рдзрд┐ рдореЗрдВ рдмрдирд╛рдпрд╛ рдЧрдпрд╛ рд╣реИ

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

RecipeDetailViewController рдирд┐рдпрдВрддреНрд░рдХред

 static NSString *AddIngredientCellIdentifier = @"AddIngredientCell"; cell = [tableView dequeueReusableCellWithIdentifier:AddIngredientCellIdentifier]; if (cell == nil) { // Create a cell to display "Add Ingredient". cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AddIngredientCellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } cell.textLabel.text = @"Add Ingredient"; 

рд╕рдВрдШрдЯрдХDetailViewController рд╕рд╛рдордЧреНрд░реА рдЬреЛрдбрд╝рдиреЗ рдФрд░ рд╕рдВрдкрд╛рджрд┐рдд рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдЬрд┐рдореНрдореЗрджрд╛рд░ рд╣реИред

IngredientDetailViewController.h
 @class Recipe, Ingredient, EditingTableViewCell; @interface IngredientDetailViewController : UITableViewController { @private Recipe *recipe; Ingredient *ingredient; EditingTableViewCell *editingTableViewCell; } @property (nonatomic, retain) Recipe *recipe; @property (nonatomic, retain) Ingredient *ingredient; @property (nonatomic, assign) IBOutlet EditingTableViewCell *editingTableViewCell; @end 

IngredientDetailViewController.m
 ... - (id)initWithStyle:(UITableViewStyle)style { if (self = [super initWithStyle:style]) { UINavigationItem *navigationItem = self.navigationItem; navigationItem.title = @"Ingredient"; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)]; self.navigationItem.leftBarButtonItem = cancelButton; [cancelButton release]; UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)]; self.navigationItem.rightBarButtonItem = saveButton; [saveButton release]; } return self; } ... - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } ... - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //   ,    return 2; } //      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *IngredientsCellIdentifier = @"IngredientsCell"; EditingTableViewCell *cell = (EditingTableViewCell *)[tableView dequeueReusableCellWithIdentifier:IngredientsCellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"EditingTableViewCell" owner:self options:nil]; cell = editingTableViewCell; self.editingTableViewCell = nil; } if (indexPath.row == 0) { cell.label.text = @"Ingredient"; cell.textField.text = ingredient.name; cell.textField.placeholder = @"Name"; } else if (indexPath.row == 1) { cell.label.text = @"Amount"; cell.textField.text = ingredient.amount; cell.textField.placeholder = @"Amount"; } return cell; } ... - (void)save:(id)sender { NSManagedObjectContext *context = [recipe managedObjectContext]; /*      -     */ if (!ingredient) { self.ingredient = [NSEntityDescription insertNewObjectForEntityForName:@"Ingredient" inManagedObjectContext:context]; [recipe addIngredientsObject:ingredient]; ingredient.displayOrder = [NSNumber numberWithInteger:[recipe.ingredients count]]; } /*        */ EditingTableViewCell *cell; cell = (EditingTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; ingredient.name = cell.textField.text; cell = (EditingTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]]; ingredient.amount = cell.textField.text; /*   */ NSError *error = nil; if (![context save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } [self.navigationController popViewControllerAnimated:YES]; } ... @end 

рдПрдХ рдШрдЯрдХ рдХреЛ рдЬреЛрдбрд╝рдиреЗ рдХреЗ рд▓рд┐рдП рдкреНрд░рдкрддреНрд░ рдирд┐рдореНрдирд╛рдиреБрд╕рд╛рд░ рд╣реИ

рдЬрдм рдЖрдк рд╕рд╣реЗрдЬреЗрдВ рдмрдЯрди рдкрд░ рдХреНрд▓рд┐рдХ рдХрд░рддреЗ рд╣реИрдВ, рддреЛ рдШрдЯрдХ рдбреЗрдЯрд╛рдмреЗрд╕ рдореЗрдВ рд╕рд╣реЗрдЬрд╛ рдЬрд╛рдПрдЧрд╛ рдФрд░ рд╕реВрдЪреА рдореЗрдВ рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд┐рдпрд╛ рдЬрд╛рдПрдЧрд╛ред рдЬрдм рдЖрдк рд░рджреНрдж рдХрд░реЗрдВ рдмрдЯрди рдкрд░ рдХреНрд▓рд┐рдХ рдХрд░рддреЗ рд╣реИрдВ, рддреЛ рдирдпрд╛ рдШрдЯрдХ рд╕рд╣реЗрдЬрд╛ рдирд╣реАрдВ рдЬрд╛рдПрдЧрд╛ред

рдореМрдЬреВрджрд╛ рд░реЗрд╕рд┐рдкреА рдХреИрд╕реЗ рдирд┐рдХрд╛рд▓реЗрдВ


RecipeListTableViewController рдирд┐рдпрдВрддреНрд░рдХ рдореЗрдВ рдПрдХ рдиреБрд╕реНрдЦрд╛ рдХреЛ рд╣рдЯрд╛рдиреЗ рдХрд╛ рд╕рдорд░реНрдерди рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдирд┐рдореНрди рдХреЛрдб рд╣реЛрддрд╛ рд╣реИред
 - (void)viewDidLoad { ... //  Edit self.navigationItem.leftBarButtonItem = self.editButtonItem; ... } ... //     UITableView - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { //    NSManagedObjectContext *context = [fetchedResultsController managedObjectContext]; [context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]]; //   NSError *error; if (![context save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } } 

рдЕрдм, рдЬрдм рдЖрдк рд╕рдВрдкрд╛рджрди рдмрдЯрди рдкрд░ рдХреНрд▓рд┐рдХ рдХрд░рддреЗ рд╣реИрдВ рдпрд╛ UITableViewCell рдкрд░ рдПрдХ рдЗрд╢рд╛рд░рд╛ рдХрд░рддреЗ рд╣реИрдВ, рддреЛ UITableView рд╕рдВрдкрд╛рджрди рдореЛрдб рдореЗрдВ рдкреНрд░рд╡реЗрд╢ рдХрд░реЗрдЧрд╛, рдЬреЛ рдЖрдкрдХреЛ рдиреБрд╕реНрдЦрд╛ рд╣рдЯрд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдЕрдиреБрдорддрд┐ рджреЗрддрд╛ рд╣реИ (рдиреАрдЪреЗ рд╕реНрдХреНрд░реАрдирд╢реЙрдЯ рджреЗрдЦреЗрдВ)ред

рдЬрдм рдЖрдк рдПрдХ рдиреБрд╕реНрдЦрд╛ рд╣рдЯрд╛рддреЗ рд╣реИрдВ, рддреЛ рдбреЗрдЯрд╛рдмреЗрд╕ рдореЗрдВ рд╕рднреА рд╕рдВрдмрдВрдзрд┐рдд рдСрдмреНрдЬреЗрдХреНрдЯ (рд╕рд╛рдордЧреНрд░реА рдФрд░ рдЪрд┐рддреНрд░) рднреА рд╣рдЯрд╛ рджрд┐рдП рдЬрд╛рдПрдВрдЧреЗред

рдореМрдЬреВрджрд╛ рдШрдЯрдХ рдХреИрд╕реЗ рдирд┐рдХрд╛рд▓реЗрдВ


RecipeDetailViewController рдирд┐рдпрдВрддреНрд░рдХ рдореЗрдВ, рд╕рдм рдХреБрдЫ рдЙрд╕реА рддрд░рд╣ рд╕реЗ рд╡реНрдпрд╡рд╕реНрдерд┐рдд рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИ, рдХреЗрд╡рд▓ рдПрдХ рддрд╕реНрд╡реАрд░ рдХреЛ рдЬреЛрдбрд╝рдиреЗ рдХреЗ рд▓рд┐рдП (рдЗрд╕реЗ рдирд╣реАрдВ рдорд╛рдирд╛ рдЬрд╛рдПрдЧрд╛)ред
 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCellEditingStyle style = UITableViewCellEditingStyleNone; // Only allow editing in the ingredients section. //    ,     (. tableView:cellForRowAtIndexPath:),      ,        ,       if (indexPath.section == INGREDIENTS_SECTION) { if (indexPath.row == [recipe.ingredients count]) { style = UITableViewCellEditingStyleInsert; } else { style = UITableViewCellEditingStyleDelete; } } return style; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //        if ((editingStyle == UITableViewCellEditingStyleDelete) && (indexPath.section == INGREDIENTS_SECTION)) { //   Ingredient *ingredient = [ingredients objectAtIndex:indexPath.row]; [recipe removeIngredientsObject:ingredient]; [ingredients removeObject:ingredient]; NSManagedObjectContext *context = ingredient.managedObjectContext; [context deleteObject:ingredient]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; } } 

рд╕рд╛рдордЧреНрд░реА рдХреЛ рдЬреЛрдбрд╝рдиреЗ рдФрд░ рд╣рдЯрд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдкреНрд░рдкрддреНрд░ рдирд┐рдореНрдирд╛рдиреБрд╕рд╛рд░ рд╣реИ


рдирд┐рд╖реНрдХрд░реНрд╖


рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ, рдореИрдВрдиреЗ рд╡рд┐рд╢реЗрд╖ рд░реВрдк рд╕реЗ рдиреБрд╕реНрдЦрд╛ рдХреЗ рд▓рд┐рдП рдПрдХ рддрд╕реНрд╡реАрд░ рдмрдирд╛рдиреЗ рдкрд░ рд╡рд┐рдЪрд╛рд░ рдирд╣реАрдВ рдХрд┐рдпрд╛ - рдкрд╛рдардХ рдХреЛ рдЗрд╕ рдХрд╛рд░реНрдпрдХреНрд╖рдорддрд╛ рдХрд╛ рд╕реНрд╡рддрдВрддреНрд░ рд░реВрдк рд╕реЗ рдЕрдзреНрдпрдпрди рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдорд╛рди рд▓реЗрдирд╛ (рджреЗрдЦреЗрдВ RecetDetailViewController рдирд┐рдпрдВрддреНрд░рдХ рдХреА рдлреЛрдЯреЛ рдЯреЗрдк рд╡рд┐рдзрд┐)ред рд╕реНрд░реЛрдд рдХреЛрдб рдХреЗ рджрд┐рдП рдЧрдП рдЙрджрд╛рд╣рд░рдг рдХреБрдЫ рдЕрдВрд╢ рд╣реИрдВред рдЖрдк рдкрд░рд┐рдпреЛрдЬрдирд╛ рдХреЛ рдбрд╛рдЙрдирд▓реЛрдб рдХрд░рдХреЗ (рд╕рдВрджрд░реНрдн рдЕрдиреБрднрд╛рдЧ рджреЗрдЦреЗрдВ) рд╕реНрд░реЛрдд рдХреЛрдб рдХрд╛ рдкреВрд░реА рддрд░рд╣ рд╕реЗ рдЕрдзреНрдпрдпрди рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдореБрдЭреЗ рдЙрдореНрдореАрдж рд╣реИ рдХрд┐ рд▓реЗрдЦреЛрдВ рдХреА рдЗрд╕ рд╢реНрд░реГрдВрдЦрд▓рд╛ рдХреЛ рд▓рд┐рдЦрдиреЗ рдореЗрдВ рдореЗрд░реЗ рджреНрд╡рд╛рд░рд╛ рдХрд┐рдпрд╛ рдЧрдпрд╛ рдХрд╛рд░реНрдп рдЖрдкрдХреЗ рд▓рд┐рдП рдЙрдкрдпреЛрдЧреА рд░рд╣рд╛ рд╣реИ - рдкреНрд░рд┐рдп рдкрд╛рдардХ! рдЖрдкрдХрд╛ рдзреНрдпрд╛рди рдФрд░ рдЖрдкрдХреЗ рдзреИрд░реНрдп рдХреЗ рд▓рд┐рдП рдзрдиреНрдпрд╡рд╛рджред

рд╕рдВрджрд░реНрдн


Source: https://habr.com/ru/post/In136344/


All Articles