条件或是否在pickerview中的语句

时间:2019-07-17 11:11:46

标签: arrays swift if-statement formula pickerview

我确实需要在这里进行逻辑的帮助,因此我在UIPickerView中使用了3个不同的数组。当用户在pickerview中选择类似的内容时,应执行某个公式(它不相关)是的 我应该使用什么?如果陈述?开关?还有一个问题。用作字符串的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
        } 

1 个答案:

答案 0 :(得分:0)

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