所有按钮都重复IBAction - 快速

时间:2016-10-09 22:01:14

标签: swift loops button ibaction

我在代码中为2个动作创建了2个按钮,然后我放了一些print()来检查我何时进入按钮动作。 问题是我在Button1上点击(并执行代码)后输入Button2。这是我的代码,我不明白..

@IBOutlet weak var Button1: UIButton!
@IBOutlet weak var Button2: UIButton!
override func viewDidLoad() {
    super.viewDidLoad()
}

/* ---------------- city picker ------------- */

@IBAction func p_cityButton(sender: AnyObject) {
    if p_cityPicker.hidden == false {
        p_cityPicker.hidden = true
        CityDoneButton.hidden = true
        CityCancelButton.hidden = true
    }
    else {
        var pickerData: [[String]] = [[String]]()
        p_cityPicker.hidden = false
        self.p_cityPicker.delegate = self
        self.p_cityPicker.dataSource = self

    pickerData = [["Ashdod", "Ashkelon", "Jerusalem", "Netanya", "Tel-Aviv"]]
    CityDoneButton.hidden = false
    CityCancelButton.hidden = false
        print("Button2")
    }

}


/* ---------------- Date Picker ------------- */
@IBAction func d_aliyahButton(sender: AnyObject) {
if d_aliyahDatePicker.hidden == false {
    d_aliyahDatePicker.hidden = true
    DateDoneButton.hidden = true
    DateCancelButton.hidden = true
}
else{
d_aliyahDatePicker.hidden = false
d_aliyahDatePicker.datePickerMode = UIDatePickerMode.Date
DateDoneButton.hidden = false
DateCancelButton.hidden = false
print("Button1")
}

如果我点击Button1,我有

  

Button1的

如果我点击Button2,我有

  

Button1的

     

将Button2

点击Button1时,我不想通过Button2。 知道我的问题在哪里吗?

Links on ctrl+click on button2

谢谢!

0 个答案:

没有答案