How to determine when the "ABC" button is pressed on the uikeyboard type "UIKeyboardTypeNumbersAndPunctuation",

I want to determine when the "ABC" button is pressed on the uikeyboard type "UIKeyboardTypeNumbersAndPunctuation", and I also want to determine when the "123" button is pressed on the letter keyboard.

I have a control "UITextview"

Pls let me thank you

+4
source share
3 answers

As far as I can tell, you do not want to replace the numbers you want to detect, the next button is pressed?

iOS email keyboard

If so, as far as I know, this is officially impossible. Apple does not provide “UIKeyboardTypeDidChange” notifications, and you cannot edit / change the “Keyboard” view while remaining within the guidelines. Your application will probably be rejected if you try.

(This does not mean that it would be impossible if you crack the keyboard screen).

+1
source

- this code only allows numbers in text mode

If you configure iOS 4.1 and later, you can use UIKeyboardTypeDecimalPad. If you need to support older versions, you need a decimal point and you no longer need anything, you will need to create a custom keyboard.

If you want to filter other keys without deleting them, assign an object as a delegate to the text field. This object should contain the following code:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet]; return([text stringByTrimmingCharactersInSet:nonNumberSet].length > 0) //or NSRange location = [string rangeOfCharacterFromSet:nonNumberSet]; return (location.location == NSNotFound); } 

for the alphabet, others you use the code above with this code ^ [0-9a-zA-Z]. I think this is useful for you. deck day

+1
source

use - (void) textViewDidChange: (UITextView *) textView delegate protocol textView. This should solve your problem.

-1
source

Source: https://habr.com/ru/post/1390006/


All Articles