我从Facebook获取用户信息,图片和用户名。我向用户显示此信息。但问题是;图片即将推迟。所以我使用SVProgressHUD
就像加载...我想在下载我的图片并向用户显示后解雇我的SVProgressHUD
。我需要使用Asynchronous
或类似的东西是什么?
这是我的代码部分;
- (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];
}
感谢您的关注和帮助。 :)
答案 0 :(得分:1)
将[SVProgressHUD dismiss]
放入完成块的结束。使用您当前的代码,进度指示器将在您向Facebook发出请求后立即解除(因为该呼叫是非阻塞的)。
答案 1 :(得分:0)
把
[SVProgressHUD dismiss];
在完成块内