这是您需要做的。这非常接近地模仿了您如何使用 NSURLConnection API 发出异步请求。
在你的 header/.h 文件中创建一个类属性(成员变量,无论你想怎么称呼它)
//header/.h file
int indexOfLastFriendLoaded;
在您的实现文件中:
- (void) loadFriend:(int) indexOfFriendToLoad {
[facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:indexOfFriendToLoad] andDelegate:self];
}
//this method is called when each facebook request finishes,
- (void)request:(FBRequest *)request didLoad:(id)result {
//first do whatever you need to with "result" to save the loaded friend data
//We make the next request from this method since we know the prior has already completed.
if (indexOfLastFriendLoaded < [self.friendIDArray count]) {
[self loadFriend:indexOfLastFriendLoaded];
indexOfLastFriendLoaded++;
}
}
- (void) viewDidLoad {
//initialize facebook object first
indexOfLastFriendLoaded = 0;
[self loadFriend:indexOfLastFriendLoaded];
}