當我使用ASIHttpRequest連接到服務器時,隱藏了modalviewcontroller的問題。 我在後臺線程連接並在主線程中顯示modalview。 這是我的代碼:使用ASIHTTPRequest隱藏modalviewcontroller的問題
[self performSelectorInBackground:@selector(loginServerRequest) withObject:nil];
- (void)loginServerRequest {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *url = [NSURL URLWithString:@"https://11.111.111.11/api/login"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[AccountSettings getCompany] forKey:@"companyName"];
[request setPostValue:[AccountSettings getEmail] forKey:@"email"];
[request setPostValue:[AccountSettings getPassword] forKey:@"password"];
[request setRequestMethod:@"POST"];
[request setTimeOutSeconds:10];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startSynchronous];
[pool drain];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
[self performSelector:@selector(hideServerConnectView) withObject:nil afterDelay:0.0];
int status = [request responseStatusCode];
NSLog(@"%i", status);
if ([self.nibName isEqualToString:@"RootViewController"]) {
if (status == 200) {
//some code
}
}
}
- (void)hideServerConnectView {
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
如果服務器響應立即modalviewcontroller絲毫不掩飾! 如果通過幾秒鐘,那麼一切都很好。 有什麼問題?
我改變了這樣的代碼:
[self loginServerRequest];
ServerConnectView *viewC = [[ServerConnectView alloc] init];
[self.view addSubview:viewC.view];
[self presentModalViewController:viewC animated:YES];
[viewC release];
- (void)loginServerRequest {
NSURL *url = [NSURL URLWithString:@"https://11.111.111.11/api/login"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:[AccountSettings getCompany] forKey:@"companyName"];
[request setPostValue:[AccountSettings getEmail] forKey:@"email"];
[request setPostValue:[AccountSettings getPassword] forKey:@"password"];
[request setRequestMethod:@"POST"];
[request setTimeOutSeconds:10];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request{
[self hideServerConnectView];
int status = [request responseStatusCode];
NSLog(@"%i", status);
if ([self.nibName isEqualToString:@"RootViewController"]) {
if (status == 200) {
//some code
}
}
}
- (void)hideServerConnectView {
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
,並沒有解決我的問題。 任何想法?或者有什麼不對?