2013-12-17 135 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

谢谢你的回答。 –