TextFieldDidBeginEditing func not called when clicking on textbox

I have a project with 3 views that are all multiple textboxes that call the UIPickerView when clicked. I have two views that work fine, but when I start from the third one, I cannot get the function textFieldDidBeginEditing

to be called. I confirmed this by putting a breakpoint on the first line of the function. When I run, the breakpoint never hits, even when I click on any of the fields in the view. I copied and pasted the code from other views, changing the variable names.

Each of the text fields is initialized in the viewDidLoad

dataPickerView variable method defined in the previous code. dataPickerView.delegate = self

and dataPickerView.dataSource = self

also.

Here is what I think is the relevant code. I'm sure there is something simple that I am missing

@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)
}

      

+3


source to share


1 answer


Have you set up a class declaration to implement the textbox delegate? Also have you set up a delegate for each field? I like to use observers as a post field, but you can also add it to viewDidLoad like you would in a password field.



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
    }
}

      

+7


source







All Articles