done button only for numberpad keyboard

后端 未结 3 1822
生来不讨喜
生来不讨喜 2020-12-18 14:44

I am working on the iPhone application. I have four textfields in one of the view. In these four textfield I have one textfield in which there will be use of numberpad keybo

3条回答
  •  悲&欢浪女
    2020-12-18 15:37

    I suppose you could keep a global variable UITextField * selectedTextField as a pointer (weak reference) to the textField the user currently has selected. Also store IBOutlets to all the UITextField object on your view (strong references). Then wrap the entire addButtonToKeyboard body in a big if clause:

    if (self.selectedTextField == self.contactNumberTextField){
        // ... add button
    }
    

    You'll need to set up the UITextField delegate method

    - (void)textFieldDidBeginEditing:(UITextField *)textField;
    

    to know which textField is the currently selected one.

    In fact I think you could even do it without the outlets, using selectedTextField.keyboardType property, but then again, you'll probably already have the outlets anyway since you need them to read user input from them.

    Hope this helps!

提交回复
热议问题