テキストフィールド ( ) に 4 つの数字を書き込みcodeA
たいのですが、中に 4 つの数字がある場合は、別のフィールド ( codeB
) を選択したいです。codeBも4桁に限定してほしい。しかし、View Controller のデリゲートにすると、アプリケーションがクラッシュします。.h の私のコード:
@property (weak, nonatomic) IBOutlet UITextField *codeA;
@property (weak, nonatomic) IBOutlet UITextField *codeB;
.m の私のコード:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([codeA.text length] > 3) {
codeA.text = [textField.text substringToIndex:4];
[codeB becomeFirstResponder];
return NO;
}
if ([codeB.text length] > 3) {
codeB.text = [codeB.text substringToIndex:4];
return NO;
}
return YES;
}
codeB
View Controllerのデリゲートでない場合は機能しますが、Bは制限されていません。