gpt4 book ai didi

arrays - pickerview 中的条件或 if 语句

转载 作者:行者123 更新时间:2023-11-30 10:39:52 26 4
gpt4 key购买 nike

我确实需要帮助来制定这里的逻辑,所以我在 UIPickerView 中使用了 3 个不同的数组。当用户在 pickerview 中选择类似的内容时,应该执行某个公式(与它无关)我应该用什么? if 语句?转变?还有一个问题。用作字符串的shiftCount数组数据会有问题吗?因为我需要将公式乘以 *1 或 *2 等。

   var shiftCount = [
"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"]

var Level = [
"White","Silver 80%","Silver 100%","Gold 80%","Gold 100%","Diamond 80%","Diamond 100%",]

var shiftDay = [

"MNG","LMNG","AFT","LAFT","PEAK","LNGT","NGT"]
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {


switch (component) {
case 0:
MyShifts = shiftCount[row]
shifts.text = "How many shifts: " + MyShifts
print(MyShifts)
case 1:
MyShiftType = shiftDay[row]
shiftType.text = "Shift you work: " + MyShiftType
print(MyShiftType)
case 2:
MyLevel = Level[row]
level.text = "Your Level: " + MyLevel
print(MyLevel)
default:
break
}

最佳答案

当您只有两个选项需要评估时,建议使用 if 语句,因此在这种情况下, switch 语句是可以的,关于您想应用公式时关于字符串数组的第二个问题,它不会出现问题是一个问题,但是你需要将该字符串转换为 Int、Double、Float 或任何类型你需要进行数学计算,如果你想在标签或类似的东西上显示它,你可以进行字符串插值来展示它。

关于arrays - pickerview 中的条件或 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57074526/

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