Answer the question
In order to leave comments, you need to log in
How to update Core Data from swift 3 table cells?
Good night!)
The task for the experienced is very simple, for me it is not entirely clear. There are 3 static cells with UITextField, how to make it so that by clicking on the "save" button - overwrite the data in the database?
//
// EditRecipeTableViewController.swift
// Customer
//
// Created by Aleksandr Govorukhin on 11.06.17.
// Copyright © 2017 Aleksandr Govorukhin. All rights reserved.
//
import UIKit
import MagicalRecord
class EditRecipeTableViewController: UITableViewController {
@IBOutlet weak var imageCollectionRecipe: UICollectionView!
var recipe: Recipe!
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 12
tableView.separatorStyle = .none
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! EditRecipeCellTableViewCell
//Отображение информации в ячейки
switch indexPath.row {
case 0:
cell.textEdit.text = self.recipe.nameRecipe
case 1:
cell.textEdit.text = self.recipe.descriptionRecipe
case 2:
cell.textEdit.text = self.recipe.sourceLink
cell.textEdit.font = UIFont.systemFont(ofSize: 12.0)
default:
print("Critical ERROR in Switch as EditRecipeTableViewController")
}
return cell
}
@IBAction func saveEditRecipe() {
}
}
Answer the question
In order to leave comments, you need to log in
@IBAction func saveEditRecipe() {
let CDataArray = newImages as! NSMutableArray
if let recipe = recipe {
if recipe.value(forKey: "nameRecipe") != nil {
recipe.setValue(textEditName.text, forKey: "nameRecipe")
}
if recipe.value(forKey: "descriptionRecipe") != nil {
recipe.setValue(textEditDescription.text, forKey: "descriptionRecipe")
}
if recipe.value(forKey: "imageRecipe") != nil {
recipe.setValue(NSKeyedArchiver.archivedData(withRootObject: CDataArray), forKey: "imageRecipe")
}
} else {
print("unable to fetch or create recipe")
}
(UIApplication.shared.delegate as! AppDelegate).saveContext()
self.goToListOfRecepies()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question