收到api响应后弹出UITextField键盘

时间:2018-01-10 10:52:25

标签: objective-c uitextfield

在我的应用程序中,我在登录屏幕中使用UITextField。要获取登录详细信息,我通过API将应用程序连接到服务器。在调用api时,我显示了一个活动UIActivityIndi​​catorView。在调用api之前我会结束编辑。一旦从服务器再次收到响应,当活动指示器停止时,键盘会弹出

这是我的代码

[self.view endEditing:YES];
VW_overlay.hidden = NO;
[activityIndicatorView startAnimating];

[self performSelector:@selector(API_Login) withObject:activityIndicatorView afterDelay:0.01];

和API_Login方法具有以下代码

-(void) API_Login
{
NSString *userEmail = _TXT_email.text;
NSString *userPWD = _TXT_password.text;
NSError *error;
NSHTTPURLResponse *response = nil;
NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",userEmail,userPWD];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSString *urlGetuser =[NSString stringWithFormat:@"%@loginApi",SERVER_URL];
NSURL *urlProducts=[NSURL URLWithString:urlGetuser];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:urlProducts];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[request setHTTPShouldHandleCookies:NO];
NSData *aData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (aData)
 {
        NSMutableDictionary *json_DATA = (NSMutableDictionary *)[NSJSONSerialization JSONObjectWithData:aData options:NSASCIIStringEncoding error:&error];
        NSLog(@"The response %@",json_DATA);
        if ([[json_DATA valueForKey:@"status"]isEqualToString:@"success"]) {
            [[NSUserDefaults standardUserDefaults] setValue:[json_DATA valueForKey:@"driver_id"] forKey:@"driver_id"];
            [[NSUserDefaults standardUserDefaults] synchronize];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[json_DATA valueForKey:@"status"] message:[json_DATA valueForKey:@"msg"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
            [alert show];

            [activityIndicatorView stopAnimating];
            VW_overlay.hidden = YES;

            [self performSelector:@selector(stop_activity) withObject:nil afterDelay:1.0];

        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[json_DATA valueForKey:@"status"] message:[json_DATA valueForKey:@"msg"] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
            [alert show];
        }
    }
    else
    {
        [activityIndicatorView stopAnimating];
        VW_overlay.hidden = YES;
        NSLog(@"Error %@\nResponse %@",error,response);
    }
    }

-(void) stop_activity
{

    [self order_details_page];
}

-(void)order_details_page
{
    [self performSegueWithIdentifier:@"login_order" sender:self];
}

0 个答案:

没有答案