我要疯了。我知道我必须从主线程更新 UI,并尝试了performSelectorOnMainThread
方法并将 progressView 更新包装在dispatch_async( dispatch_get_main_queue(), ^{ update progressView });
//facebook request
FBRequest *friendsRequest = [FBRequest requestForGraphPath:@"me/friends?fields=id,name,birthday"];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
//user's friends
NSArray *friends = [result objectForKey:@"data"];
//counter
int i = 0;
//iterate through array of friends
for (NSDictionary<FBGraphUser> *friend in friends)
{
//do some work here
//update progressView
float progress = (float)i/(float)[friends count];
[[self progressView] setProgress:progress animated:YES];
i++;
}
}];
谢谢!