开发者

UITextField selectAll and no menu after tap on another uitextfield

开发者 https://www.devze.com 2023-03-26 19:52 出处:网络
I have some开发者_如何学Python UITextField that when the user tap on it, I select all the text and the menu is hidden, but if they don\'t make any change, when they tap on another UITextField, the men

I have some开发者_如何学Python UITextField that when the user tap on it, I select all the text and the menu is hidden, but if they don't make any change, when they tap on another UITextField, the menú Cut, Copy, Replace appears on the current UITextfield, not in the tapped UITextfield.

I can hide the menu the first time just after the selectAll, but not when the user taps on another UITextfield.

Any ideas ?

thanks,

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

   [textField selectAll:textField];
   [UIMenuController sharedMenuController].menuVisible = NO;

}


Did you set the delegate for the other text field(s)?

Example: myTextField.delegate = self;


The textField variable in the delegate method should be the second UITextField when touched. You can identify your UITextFields with tags. Thus:

#define kSecondTextFieldTag 300
// ....

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == kSecondTextFieldTag) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

Yeah, and make sure you set the delegates as suggested before.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号