I need help. My Recipe app has a main viewController with two UITableView
(ingredientTableView
and directionTableView
). Each is populate from two modal view controllers by 'segue'.
The data are storage in the ingredient/direction array of new recipe, but the UITableView
not display the text when dismissing the modal view.
The 'Save' UIBarButton
code of newRecipeController
:
// MARK: - IBActions
extension AddNewRecipeViewController {
// MARK: - Add Ingredient
@IBAction func saveIngredient(_ segue: UIStoryboardSegue)
{
guard let addIngredientModalViewController = segue.source as? AddIngredientModalViewController,
let ingredient = addIngredientModalViewController.ingredient else
{
return
}
// add the new ingredient to the ingredients array
ingredients.append(ingredient)
// update the tableview
let indexPath = IndexPath(row: ingredients.count - 1, section: 0)
ingredientTableView.insertRows(at: [indexPath], with: .automatic)
}
@IBAction func cancelAddIngredient(_ segue: UIStoryboardSegue)
{
dismiss(animated: true, completion: nil)
}
This is the prepare for segue code of a modal view:
// MARK: - Segue AddIngredient
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier == "SaveIngredient",
let ingredientName = fieldAddNameIngredient.text,
let ingredientValue = fieldValueOfIngredient.text
{
ingredient = IngredientModel(titleIngredientRecipe: ingredientName, subtitleIngredientRecipe: ingredientValue)
}
}