【问题标题】:identifying specific UITextField with delegate用委托识别特定的 UITextField
【发布时间】:2017-06-23 18:59:07
【问题描述】:

我有两个带有代表的 UITextfields。 我需要能够在下面的基金中识别它们,因此只有其中一个会打开 datePicker(暂时评论)。我该怎么做?

func textFieldDidBeginEditing(_ textField: UITextField) {
        //******************************************
        //******************************************
        //uncomment this for date to work
        /*
        let datePicker = UIDatePicker()
        datePicker.datePickerMode = .date
        textField.inputView = datePicker
        datePicker.addTarget(self, action: #selector(datePickerChanged(sender:)), for: .valueChanged)
 */
}

【问题讨论】:

    标签: ios swift3 xcode8


    【解决方案1】:

    两种选择:

    • 添加标签并检查if textField.tag == 100 { ...
    • 为其中一个添加IBOutlet 并检查if textField == myTextField { ...

    【讨论】:

      【解决方案2】:

      我认为您可以通过比较传递给委托方法的文本字段来处理此问题。

      大意是:

      if myTextField {
      do action
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多