0

3 つのセグメント化されたコントロール (ゲーム名) と、価格、数量、小計用の 3 つのテキスト フィールドがあります。また、1から5の間で数量を増減するためのステッパーが1つあります。

1 つのゲームの数量を変更して別のゲームを選択すると、問題が発生します。game1 の数量を 5 に増やし、ゲームを変更したとします。数量フィールドは自動的に 1 に設定されます。しかし、ステッパーの「+」は選択できず、ステッパーの「-」を押すと数量が4になります。

セグメント化されたコントロールからゲームを変更するときに、ステッパーの値を更新する必要があります。何か案が ?

    class ViewController: UIViewController {

        @IBOutlet weak var Photo: UIImageView!
        @IBOutlet weak var seg_games: UISegmentedControl!
        @IBOutlet weak var lbl_motto: UILabel!
        @IBOutlet weak var txt_unitPrice: UITextField!
        @IBOutlet weak var txt_quantity: UITextField!
        @IBOutlet weak var txt_totalPrice: UITextField!
        @IBOutlet weak var step_qChooser: UIStepper!


        @IBAction func stepChanged(sender: UIStepper) {


            if (txt_quantity.text.isEmpty) {
                let alert = UIAlertView()
                alert.title = "No Game Choose"
                alert.message = "Please Pick Your Game First !"
                alert.addButtonWithTitle("Ok")
                alert.show()
            }

            else {

            txt_quantity.text = Int(sender.value).description
            txt_totalPrice.text = TotalCalc()

            }
        }

        func TotalCalc () -> String {
            var a = txt_unitPrice.text.toInt()
            var b = txt_quantity.text.toInt()
            var sonuc = a! * b!
            return String(sonuc)
        }


        @IBAction func seg_games(sender: AnyObject) {

            var index = seg_games.selectedSegmentIndex
            var choice = seg_games.titleForSegmentAtIndex(index)!

            if choice == "Fallout"
            {
                lbl_motto.text = "Be Prepare your P.I.M.P."
                self.Photo.image = UIImage(named: "fallout.png")
                txt_quantity.text = "1"
                txt_unitPrice.text = "80"

                txt_totalPrice.text = TotalCalc()

            }

            else if choice == "Borderlands"
            {
                lbl_motto.text = "Ready for BIG BOYS !!!"
                self.Photo.image = UIImage(named: "borderlands.png")
                txt_quantity.text = "1"
                txt_unitPrice.text = "55"

                txt_totalPrice.text = TotalCalc()

            }

            else if choice == "Battlefield"

            {
                lbl_motto.text = "Choose: Sniper or Assult"
                self.Photo.image = UIImage(named: "battlefield.png")
                txt_quantity.text = "1"
                txt_unitPrice.text = "110"

                txt_totalPrice.text = TotalCalc()

            }

        }
4

1 に答える 1