Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 点击文本字段时,未调用textFieldDidBeginEditing func_Ios_Swift_Uitextfield - Fatal编程技术网

Ios 点击文本字段时,未调用textFieldDidBeginEditing func

Ios 点击文本字段时,未调用textFieldDidBeginEditing func,ios,swift,uitextfield,Ios,Swift,Uitextfield,我有一个项目,有三个视图,都是多个文本字段,点击时调用UIPickerView。我有两个视图工作得很好,但是当我开始使用第三个视图时,我无法调用textfielddebeginediting函数。我通过在函数的第一行放置断点来确认这一点。当我运行时,断点永远不会被击中,即使我点击视图中的任何字段。我从其他视图复制并粘贴了代码,更改了变量名 在viewDidLoad方法中将每个文本字段初始化为前面代码中定义的dataPickerView变量。dataPickerView.delegate=self

我有一个项目,有三个视图,都是多个文本字段,点击时调用UIPickerView。我有两个视图工作得很好,但是当我开始使用第三个视图时,我无法调用
textfielddebeginediting
函数。我通过在函数的第一行放置断点来确认这一点。当我运行时,断点永远不会被击中,即使我点击视图中的任何字段。我从其他视图复制并粘贴了代码,更改了变量名

viewDidLoad
方法中将每个文本字段初始化为前面代码中定义的dataPickerView变量。
dataPickerView.delegate=self
dataPickerView.dataSource=self

以下是我认为相关的代码。我确信我遗漏了一些简单的东西

@IBOutlet var enterDispPhys: UITextField!
@IBOutlet var enterUser: UITextField!
@IBOutlet var enterInsurance: UITextField!
@IBOutlet var enterBodyPart: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    self.userLabel.text = userName
    self.teamLabel.text = teamName

    //initialize the inputView of the dispensing physician field to the PickerView
    enterDispPhys.inputView = dataPickerView

    //initialize the inputView of the user name field to the PickerView
    enterUser.inputView = dataPickerView

    //initialize the inputView of the insurance field to the PickerView
    enterInsurance.inputView = dataPickerView

    //initialize the inputView of the body part field to the PickerView
    enterBodyPart.inputView = dataPickerView

    dataPickerView.delegate = self
    dataPickerView.dataSource = self
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func textFieldDidBeginEditing(textField: UITextField) {
    activeDataArray == [] //clear out the clicked field data array
    if textField == enterDispPhys {
        activeDataArray = dispPhys
    } else
        if textField == enterUser {
            activeDataArray = userNameList
    } else
        if textField == enterInsurance {
            activeDataArray = insCode
    } else
        if textField == enterBodyPart {
            activeDataArray = bodyPart
    }
    dataPickerView.reloadAllComponents()
    dataPickerView.hidden = false
    println(activeDataArray)
}

您是否设置了类声明以实现文本字段委托?您是否为每个字段设置了代理?我喜欢使用观察者作为电子邮件字段bellor,但您也可以将其添加到viewDidLoad中,就像在密码字段中一样

class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var email: UITextField!{
        didSet{email.delegate = self}
    }
    @IBOutlet weak var password: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        password.delegate = self
    }
}

是的,我在类声明中实现了UIExtFieldDelegate、UIPickerViewDelegate和UIPickerViewDataSource。是否为每个文本字段设置了所有委托?我在上面添加答案您的问题的答案是否,我没有每个textField.delegate=self。然而,在我使用这种技术的其他两个视图中,我以相同的方式设置文本字段。从代码中,每个textFields.inputView=dataPickerView。为什么在这个视图中我需要为每个textField的委托添加代码,而不是在其他视图中?我编辑了原始帖子以显示IBOutlet代码。我认为更好的问题是,另一个视图是如何工作的,因为textfield要响应其委托,您必须将其委托设置为您希望其响应的类。我选择了第一个解决方案作为IBOutlet的一部分。我仍然不知道为什么这个观点需要这样做,而其他观点则不需要。我已经将代码并排进行了比较,没有发现遗漏任何一步。谢谢你的帮助。