Я создаю приложение для приготовления пищи, которое содержит несколько различных рецептов. поскольку
Мне нужно будет создать контроллер представления для каждого рецепта / еды, он будет дублировать множество представлений, таких как просмотр изображений, просмотр текста и т. Д. Могу ли я иметь одно представление для взаимного обмена рецептами? И как бы я назвал конкретный рецепт и его изображение, ингредиенты, название и т. Д.?
Кстати, я новичок в Swift, так что если кто-то может объяснить, как это сделать?
Обновление:
Это то, что я имею до сих пор. Как мне вернуть один конкретный рецепт на BasicBreakfastViewController
?
class Recipes: NSObject {
var recipeName = ""
//name of recipe
var prepTime = ""
//preparation time
var imageFile = ""
//image filename of recipe
var ingredients: [Any] = []
// ingredients
var step1 = ""
var step2 = ""
//recipe directions
var calories: Int = 0
}
//BreakfastRecipesViewController
class BreakfastRecipesViewController: UIViewController{
var recipe: Recipes?
@IBOutlet weak var recipeImage: UIImageView!
@IBOutlet weak var prepTimeLabel: UILabel!
@IBOutlet weak var caloriesLabel: UILabel!
@IBOutlet weak var recipeTitle: UILabel!
@IBOutlet weak var directionStep1: UILabel!
@IBOutlet weak var directionStep2: UILabel!
@IBOutlet weak var ingredientsTableView: UITableView!
@IBOutlet weak var addToListBtn: UIButton!
@IBAction func handleSwipe(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
let riceCakeRecipe = Recipes()
riceCakeRecipe.recipeName = "PEANUT BUTTER AND BANANA RICE CAKE"
riceCakeRecipe.prepTime = "5 Minutes"
riceCakeRecipe.imageFile = "IMG_273711.JPG"
//riceCakeRecipe.calories = 281
riceCakeRecipe.ingredients = ["• 2 Rice Cakes", "• 2 Tbsp Peanut Butter", "• 1/2 Banana"]
riceCakeRecipe.step1 = "Distribute peanut butter evenly onto the rice cakes."
riceCakeRecipe.step2 = "Chop half of a banana and place on top of peanut butter."
let proteinBarkRecipe = Recipes()
proteinBarkRecipe.recipeName = "FROZEN YOGURT PROTEIN BARK"
proteinBarkRecipe.prepTime = "15 Minutes"
proteinBarkRecipe.imageFile = "IMG_298611.JPG"
//riceCakeRecipe.calories = 364
proteinBarkRecipe.ingredients = ["• 1 Cup Greek Yogurt", "• 32g Vanilla Protein Powder", "• 5 Large Fresh Strawberries", "• 1 Tbsp Dark Chocolate", "• 1 Tsp Coconut Flakes"]
proteinBarkRecipe.step1 = "Mix the yogurt and protein powder together until well combined."
proteinBarkRecipe.step2 = "Line a baking sheet with foil and spread a thick layer of the yogurt mixture on top."
var recipes = [riceCakeRecipe, proteinBarkRecipe]
recipeTitle.text = recipe?.recipeName
prepTimeLabel.text = recipe?.prepTime
recipeImage.image = UIImage(named: recipe!.imageFile)
directionStep1.text = recipe?.step1
directionStep2.text = recipe?.step2
//caloriesLabel.text = recipe?.calories
return
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}