我正在开发一个登录应用程序。我有一个注册视图,我正在使用 sendAsynchronousRequest 发送注册请求。当我收到返回的数据时,我想显示警报视图以显示注册(如果有效)。现在我的问题是当我收到返回的数据时,UI 会被阻止,直到显示警报视图。
为什么会发生这种情况,我该如何解决?检查代码片段:
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
error = connectionError;
NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil ];
if ([dic count] == 1) {
[dic valueForKey:@"RegisterUserResult"];
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Registration" message:[dic valueForKey:@"RegisterUserResult"] delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alertview show];
}else {
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Registration" message:[dic valueForKey:@"ErrorMessage"] delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
[alertview show];
}
[self printData:data];