을 반환합니다. -(void)registerUser
메서드에서 2 개의 UITextField와 Ok 버튼이있는 모달 뷰를 제공합니다.UITextField canBecomeFirstResponder는 NO
UITextFields를 채운 다음 Ok 버튼을 눌러 위임 메서드 -(void)AEMUserRegistrationVCUserName:(NSString *)un password:(NSString *)pw
을 호출하여 서버에 연결하는 데이터를 확인합니다.
대답이 -(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
에 도착하면 데이터가 잘못되었을 경우 self.userRegistrationVC.userName becomeFirstResponder]
으로 UITextfield에 포커스를 설정하려고하지만 포커스를 얻지 못합니다.
나는 [self.userRegistrationVC.userName canBecomeFirstResponder]
을 확인했으며, 그렇지 않은 경우에는 문서를 반환한다는 것을 나타내는 NO가 반환됩니다.
내 코드는 참고로 여기에 있습니다 :
참고 :
self.userName
및 selfPassword
이 NSStrings. self.userRegistrationVC
은 UIViewController입니다. self.userRegistrationVC.userName
및 self.userRegistrationVC.password
은 UITextfields입니다.
-(void)registerUser
{
//Recuperar el nombre de usuario
self.userName = [[NSUserDefaults standardUserDefaults] objectForKey:kNombreUsuario];
if (!self.userName) {
//No hay nombre de usuario, el usuario nunca ha registrado la aplicación.
if (!self.userRegistrationVC) {
//Solicitar datos de registro
self.userRegistrationVC = [[AEMUserRegistrationViewController alloc] initWithNibName:@"AEMUserRegistrationViewController" bundle:nil];
}
self.userRegistrationVC.delegate = self;
[self.viewControllerToPresentModalView presentModalViewController:self.userRegistrationVC animated:YES];
return;
}
//Recuperar la contraseña
NSError *error;
self.password = [SFHFKeychainUtils getPasswordForUsername:self.userName andServiceName:kServiceName error:&error];
if (!self.password) {
//No hay contraseña. La contraseña se ha perdido.
if (!self.userRegistrationVC) {
//Solicitar datos de registro
self.userRegistrationVC = [[AEMUserRegistrationViewController alloc] initWithNibName:@"AEMUserRegistrationViewController" bundle:nil];
}
self.userRegistrationVC.delegate = self;
[self.viewControllerToPresentModalView presentModalViewController:self.userRegistrationVC animated:YES];
return;
}
//Los datos del usuario existen
//Verificar el registro
[self.client get:kConfirmUsuario
queryParams:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:self.userName, self.password, nil]
forKeys:[NSArray arrayWithObjects:kNombreUsuario, kPassword, nil]]
delegate:self];
}
-(void)AEMUserRegistrationVCUserName:(NSString *)un password:(NSString *)pw
{
//El usuario ha introducido datos de registro
//Realizar el registro
self.userName = un;
self.password = pw;
[self.client get:kCreateUsuario
queryParams:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:self.userName, self.password, nil]
forKeys:[NSArray arrayWithObjects:kNombreUsuario, kPassword, nil]]
delegate:self];
//No hacer dismiss ahora esperar a verificar el registro
}
-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
//Puede responder a createUsuario o a confirmUsuario
//En ambos casos el error impide registrar al usuario y ejecutar el programa
BOOL isRequestCreateUser;
NSRange aRange = [request.resourcePath rangeOfString:kCreateUsuario];
if (aRange.location != NSNotFound) {
//The request was to create a user
isRequestCreateUser = YES;
} else {
//The request was to check a user
isRequestCreateUser = NO;
}
if (response.isConflict) {
//Error
[self.userRegistrationVC.userNameError setHidden:NO];
if ([self.userRegistrationVC.password canResignFirstResponder]) {
NSLog(@"SI"); //This return NO
}
if ([self.userRegistrationVC canBecomeFirstResponder]) {
NSLog(@"SI"); //This returns NO
}
[self.userRegistrationVC.userName becomeFirstResponder];
}
if (response.isServerError) {
//Error
[self.userRegistrationVC.userNameError setHidden:NO];
[self.userRegistrationVC.userName becomeFirstResponder];
}
if (response.isOK) {
//Success
//Retirar la pantalla de registro de usuario
[self.viewControllerToPresentModalView dismissModalViewControllerAnimated:YES];
//Si la peticion fue crear un usuario
if (isRequestCreateUser) {
//Guardar el nombre de usuario en las preferencias del usuario
[[NSUserDefaults standardUserDefaults] setValue:self.userName forKey:kNombreUsuario];
//Guardar la contraseña en KeyChain
[SFHFKeychainUtils storeUsername:self.userName andPassword:self.password forServiceName:kServiceName updateExisting:YES error:nil];
}
[self.delegate AEMUserRegistrationSucess];
}
}
통화의 순서는 다음과 같습니다
- - (무효) registerUser
- - (무효) AEMUserRegistrationVCUserName : (있는 NSString *)되지 않은 암호 (있는 NSString *) PW
- - (void) 요청 : (RKRequest *) 요청 didLoadResponse : (RKResponse *) 응답
포럼 읽기 많은 질문에 [ UITextField becomeFirstResponder] 솔루션으로, 그래서 내가 뭔가 중요한 놓친거야, 그리고 그것을 작동하게 만들 수 없습니다.
문서에서는 canBecomeFirstResponder를 재정 의하여 YES를 반환 할 수 있다고하지만 UITextField 메서드를 재정의하려면 어떻게해야합니까? 이 일을해야합니까?