2013-12-17 178 views
0

我從Facebook獲取用戶信息,這是圖片和用戶名。我告訴用戶這些信息。但問題是,圖片即將推遲。因此,我使用SVProgressHUD就像正在加載...我想要關閉我的SVProgressHUD後下載我的照片並顯示用戶。我需要使用Asynchronous或類似的東西?下載數據異步ios

這是我的代碼部分;

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

RoundedImageView *profileImageView = [[RoundedImageView alloc] initWithFrame:CGRectMake(27, 80, 70, 70)]; 

_userNameLabel.hidden = YES; 
profileImageView.hidden = YES; 
[SVProgressHUD showWithStatus:@"Loading..."]; 

//[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(LoadingDismiss) userInfo:nil repeats:NO]; 

[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) { 
    if (error) { 
     // Handle error 
    } 

    else { 
     NSString *username = [FBuser name]; 
     NSLog(@"username = %@",username); 

     NSString *userBirtday = [FBuser birthday]; 
     NSLog(@"birthday = %@",userBirtday); 

     NSString *email = [FBuser objectForKey:@"email"]; 
     NSLog(@"email = %@",email); 

     NSString *userID = [FBuser objectForKey:@"id"]; 
     NSLog(@"userID = %@",userID); 
     //==========================================================================ResimAlma 
     NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=normal", userID]; 
     NSURL * imageURL = [NSURL URLWithString:userImageURL]; 
     NSData * imageData = [NSData dataWithContentsOfURL:imageURL]; 
     UIImage *image = [UIImage imageWithData:imageData]; 



     //Configring the rounded imageview by setting appropriate image and offset. 
     profileImageView.imageOffset = 2.5; 
     profileImageView.image = image; 
     profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"]; 

     [self.view addSubview:profileImageView]; 

     if (image == nil) { 

      profileImageView.imageOffset = 2.5; 
      profileImageView.image = [UIImage imageNamed:@"noImage.png"]; 
      profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"]; 

     }else{ 
      profileImageView.imageOffset = 2.5; 
      profileImageView.image = image; 
      profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"]; 

     } 

     _userNameLabel.text = username; 

     _userNameLabel.hidden = NO; 
     profileImageView.hidden = NO; 

    } 
}]; 

[SVProgressHUD dismiss]; 

} 

感謝您的關注和幫助。 :)

回答

1

[SVProgressHUD dismiss]放在您的完成塊的結束。使用您當前的代碼,在向Facebook發出請求後,進度指示器會立即消失(因爲該呼叫是非阻塞的)。

+0

怎麼會不我認爲......非常感謝您的回答。它的工作 –

+0

很高興幫助!請接受答案,如果它解決了問題:) – Macondo2Seattle

+0

是的,我會,但我必須等6分鐘:) –

0

[SVProgressHUD dismiss]; 

您完成塊內

+0

謝謝你的回答。 –