使用Swift,为什么当按下一个UIStepper会影响两个步进器?

问题描述:

我正在使用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

也许你与两个步进器的@IBAction相同。 见下图shot-

enter image description here