Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在单击按钮后将4个滑块值相加_Swift_Uilabel_Uislider - Fatal编程技术网

Swift 在单击按钮后将4个滑块值相加

Swift 在单击按钮后将4个滑块值相加,swift,uilabel,uislider,Swift,Uilabel,Uislider,我有4个滑块,4个标签反映滑块值。当我单击情节提要上的“提交”按钮时,我希望标签“mathvalue”(总数点旁边的0)显示滑块输入的添加整数总数。这是可能的还是有另一种方式,可能没有滑块,工作效率更高?我问了一个与此主题相关的不太具体的问题,得到了一个有效的答案,但只有一个变量,如果可以改进,允许添加4个值,那就太好了 `var aValue: Int { didSet { mathCriAValue.text = "\(aValue)" } } @IBAction fu

我有4个滑块,4个标签反映滑块值。当我单击情节提要上的“提交”按钮时,我希望标签“mathvalue”(总数点旁边的0)显示滑块输入的添加整数总数。这是可能的还是有另一种方式,可能没有滑块,工作效率更高?我问了一个与此主题相关的不太具体的问题,得到了一个有效的答案,但只有一个变量,如果可以改进,允许添加4个值,那就太好了

 `var aValue: Int {
  didSet {
     mathCriAValue.text = "\(aValue)"
  }
}

@IBAction func mathCriAChanged( sender: UISlider) {
   aValue = Int(sender.value)
}`
//
//  ViewController.swift
//  InnovationSS
//
//  Created by AJ Admin on 8/16/18.
//  Copyright © 2018 AJ Admin. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
   //The slider that the students will use to input their grades into the app
    @IBOutlet weak var MathCriASlider: UISlider!
    @IBOutlet weak var MathCriAValue: UILabel!

    //label is now equal to value of slider
    @IBAction func MathCriAChanged(_ sender: UISlider) {
        let currentValue = Int(sender.value)

        MathCriAValue.text = "\(currentValue)"
    }

    @IBOutlet weak var MathCriBSlider: UISlider!
    @IBOutlet weak var MathCriBValue: UILabel!

    @IBAction func MathCriBChanged(_ sender: UISlider) {
        let currentValue = Int(sender.value)

        MathCriBValue.text = "\(currentValue)"
    }

    @IBOutlet weak var MathCriCSlider: UISlider!
    @IBOutlet weak var MathCriCValue: UILabel!

    @IBAction func MathCriCChanged(_ sender: UISlider) {
        let currentValue = Int(sender.value)

        MathCriCValue.text = "\(currentValue)"
    }

    @IBOutlet weak var MathCriDSlider: UISlider!
    @IBOutlet weak var MathCriDValue: UILabel!

    @IBAction func MathCriDChanged(_ sender: UISlider) {
        let currentValue = Int(sender.value)

        MathCriDValue.text = "\(currentValue)"
    }

    @IBOutlet weak var mathValue: UILabel!

    var aValue: Int = 0 {
        didSet {
            MathCriAValue.text = "\(aValue)"
        }
    }
    var bValue: Int = 0 {
        didSet {
            MathCriBValue.text = "\(bValue)"
        }
    }
    var cValue: Int = 0 {
        didSet {
            MathCriCValue.text = "\(cValue)"
        }
    }
    var dValue: Int = 0 {
        didSet {
            MathCriDValue.text = "\(dValue)"
        }
    }

    @IBAction func mathValueChanged(_ sender: UISlider) {
        aValue = Int(sender.value)
    }
}

你的按钮处理程序在哪里?你想从哪里得到总数?你到底有什么问题?按钮处理程序?我尝试了另外两次,但删除了它们,因为它们不起作用或在我的应用程序中引起了其他问题。每次我尝试使用整数值和任何UI标签/滑块/按钮执行任何操作时,都会出现错误。请用您尝试过的内容更新您的问题,并清楚地指出您存在的问题。编辑它,添加上一个问题的答案,只使用一个值。