Comment limiter UITextField à l'anglais uniquement? (Arrêt de l'input pinyin chinois)

Je construis une application pour la sortie à Taiwan, donc ce sera principalement en chinois, mais les noms d'users doivent être en anglais. Je ne suis pas sûr de savoir comment empêcher les caractères chinois d'être saisis. Jusqu'à présent, j'ai limité la longueur du nom d'user à 12 caractères et les caractères doivent être dans l'set défini ci-dessous:

#define ACCEPTABLE_CHARACTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 

J'ai implémenté le – (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range rlocationSsortingng: (NSSsortingng *) méthode de string et maintenant mon UITextField fonctionne pour les deux conditions ci-dessus. Cependant, bien qu'un caractère chinois ne soit pas dans l'set, il apparaît toujours en raison de pinyin étant utilisé pour taper est l'anglais. c'est-à-dire que 李 est li, donc je suis capable de taper l puis i, puis le caractère chinois 李 apparaît. Y a-t-il moyen de contourner cela? Toute aide serait grandement appréciée. Merci

Essayez de définir le type de keyboard du champ de saisie

 UITextField *tf = [[UITextField alloc] initWithFrame:CGRectZero]; tf.keyboardType = UIKeyboardTypeASCIICapable; 

utilisé ceci

 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementSsortingng:(NSSsortingng *)ssortingng{ NSCharacterSet *numbersOnly = [NSCharacterSet characterSetWithCharactersInSsortingng:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"]; NSCharacterSet *characterSetFromTextField = [NSCharacterSet characterSetWithCharactersInSsortingng:ssortingng]; BOOL ssortingngIsValid = [numbersOnly isSupersetOfSet:characterSetFromTextField]; if(ssortingngIsValid){ return yes; else return no; }