2011-12-02 9 views
0

我想顯示一個UIAlertView,而LoginProcess正在工作或調用loginButton動作後。這裏是我的代碼:UIAlertView出現toooo短之後loginButton動作調用

- (void) btnLogin:(id) sender { 

    UIAlertView *alertLogin = [[UIAlertView alloc] initWithTitle:nil message:@"\nLogin in progress, please wait!" delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
    [alertLogin show]; 

    NSURL *url = [NSURL URLWithString:@"http://www.example.com/login/"]; 

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 

    [request setPostValue:username forKey:@"username"]; 
    [request setPostValue:password forKey:@"pw"]; 

    [request startSynchronous]; 
    [request cancelAuthentication]; 

    [...] 
} 
  1. 我按下登錄按鈕。
  2. 屏幕得到一個灰色的徑向覆蓋

3. loginprogress完成現在的UIAlertView中顯得很很快。

我想顯示UIView WHILE登錄正在進行中,而不是之後。 我無法找出進展後出現的原因。
需要幫助。
非常感謝您的任何建議。

回答

3

在.H類

UIAlertView *alert; 

的在.M btnLogin方法

alert = [[[UIAlertView alloc] initWithTitle:@"Login in progress\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease]; 

[警報顯示]

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 

// Adjust the indicator so it is up a few pixels from the bottom of the alert 
indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height - 50); 
[indicator startAnimating]; 
[alert addSubview:indicator]; 
[indicator release]; 

在連接didRecieveData方法,你會寫,或者如果你正在解析,然後解析器didEndDocument方法,你可以做

[alert dismissWithClickedButtonIndex:0 animated:YES]; 
+0

你好Veer,這是行不通的。屏幕在登錄進程/加載時被阻止。你有推薦MBProgressHUD,但也有同樣的問題。 – brush51

0

你的問題是在[request startSynchronous];

同步HTTP請求和用戶界面不能很好地結合在一起。嘗試使用和異步連接

+0

我也試過,但那不是解決問題。 – brush51

相關問題