gpt4 book ai didi

ios - 获取用于编辑的 uiSegmentControl 值

转载 作者:行者123 更新时间:2023-11-28 05:57:14 25 4
gpt4 key购买 nike

我有一个分段控件来定义准备食谱的难度级别。我需要在一个我不会对其进行编辑的配方中加载赋值。遵循代码:

@IBOutlet var segNewDifficultyLevel: UISegmentedControl!

@IBOutlet var ingredientTableView: UITableView!
@IBOutlet var directionTableView: UITableView!

weak var delegate: AddNewRecipeViewControllerDelegate?

// MARK: - Variabili Globali
var editRecipe: RecipeModel!

var difficultyLevel: String!

var ingredients: [IngredientModel] = []
var directions: [DirectionModel] = []

此代码在 viewDidLoad 中:

if let editToRecipe = editRecipe {
title = "Edit Recipe"
// Load data from Recipe Detail into editRecipe
viewImageNewRecipe.image = editToRecipe.imageRecipe
fieldNewRecipeName.text = editToRecipe.nameRecipe
fieldNewQuantityFor.text = editToRecipe.quantityRecipe
fieldNewPrepareTime.text = editToRecipe.preparationTime
fieldNewCookingTime.text = editToRecipe.cookingTime
fieldNewBakingTemp.text = editToRecipe.bakingTempRecipe

/* Load the Difficulty Level selected in the recipe */
segNewDifficultyLevel.selectedSegmentIndex = ???

有人可以帮帮我吗?非常感谢!!!

配方模型类:

class RecipeModel: NSObject, NSCoding
{
var nameRecipe: String
var quantityRecipe: String
var recipeTime: String
var preparationTime: String
var cookingTime: String
var bakingTempRecipe: String

var difficultyLevelRecipe: String

var imageRecipe: UIImage

var ingredients: [IngredientModel]
var directions: [DirectionModel]

var recipeTimeInt: Int
{
var sumRecipeTime: Int = Int(recipeTime)!
sumRecipeTime = Int(preparationTime)! + Int(cookingTime)!
return sumRecipeTime
}

init(nameRecipe: String, quantityRecipe: String, recipeTime: String, preparationTime: String, cookingTime: String, bakingTempRecipe: String, difficultyLevelRecipe: String, imageRecipe: UIImage, ingredients: [IngredientModel], directions: [DirectionModel]) {
self.nameRecipe = nameRecipe
self.quantityRecipe = quantityRecipe
self.recipeTime = recipeTime
self.preparationTime = preparationTime
self.cookingTime = cookingTime
self.bakingTempRecipe = bakingTempRecipe
self.difficultyLevelRecipe = difficultyLevelRecipe
self.imageRecipe = imageRecipe
self.ingredients = ingredients
self.directions = directions
}

...

最佳答案

如果您在 difficultyLevelRecipe 中将索引作为字符串获取,那么您可以将其转换为 IntselectedSegmentIndex 设置的值,如下所示:

segNewDifficultyLevel.selectedSegmentIndex = Int(editToRecipe.difficultyLevelRecipe)

但是,如果您得到一些其他值,例如 difficultyLevelRecipe 的值/名称,那么您需要根据 segNewDifficultyLevel 中可用的值/名称来设置它。您需要根据条件通过比较段名称和您的 difficultyLevelRecipe 来管理它。

希望你思路清晰,明白该怎么做。

关于ios - 获取用于编辑的 uiSegmentControl 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51117569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com