2017-09-14 54 views
0

我正在使用xCode在Swift 3.0中編寫應用程序。使用Swift,爲什麼當按下一個UIStepper會影響兩個步進器?

我在iPhone上有兩個步進器,當我按下其中一個時,兩個文本框都會受到影響。我只想要一個文本框受到影響。 ]

它與sender.value有關嗎?當我只想要一個標籤受到影響時,我該如何具體說明?

這裏是我的代碼:

//the birthdate action that will increase or decrease the age 
@IBAction func birthdateStepperAction(_ sender: UIStepper) { 
    //when the age stepper is pressed, the value is sent to the textbox 
    actualAgeLbl.text = String(sender.value) 
} 

//the weight action that will increase or decrease the weight 
@IBAction func weightStepperAction(_ sender: UIStepper) { 
    //when the weight stepper is pressed, the value is sent to the textbox 
    actualWeightLbl.text = String(sender.value) 
} 

這裏是按步進前: first picture before pressing stepper

這裏是按步進 second picture after pressing stepper

在此先感謝後。

+2

我「猜」的,既是連接一個或兩個你'IBAction'的 - 檢查你的'UIStepper's和腳都的「連接檢查」什麼「值已更改「(我認爲)屬性鏈接到 – MadProgrammer

+1

這可能是因爲您複製了一個已連線的步進器,然後又添加了第二個連接。在故事板中,按住Control鍵並單擊步進器,然後在彈出窗口中查看連接到「Value Changed」的內容。點擊要斷開連接的功能旁邊的(x)。 – vacawama

回答

1

也許你與兩個步進器的@IBAction相同。 見下圖shot-

enter image description here

相關問題