0

我真的需要帮助来制作这里的逻辑,所以我有 3 个不同的数组,我在我的UIPickerView.当用户在选择器视图中选择这样的东西时,应该执行某个公式(它不相关)我应该使用什么? 如果语句?转变?还有一个问题。用作字符串的 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
        } 
4

1 回答 1

0

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

于 2019-07-17T15:42:54.740 回答