从FBRequest CompletionHandler更新UIProgressView

时间:2014-03-15 10:32:53

标签: ios facebook block uiprogressview completionhandler

对此我很生气。我知道我必须从主线程更新UI并尝试performSelectorOnMainThread方法并在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++;
    }
}];

谢谢!

0 个答案:

没有答案