這是你需要做的。這非常接近地模仿你如何使用NSURLConnection API進行異步請求。
在你的頭/ .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];
}
我做的,我用的是didLoad方法,但它只在最後執行一次。我想因爲我的循環太快發出請求,搞亂了響應? – user339946 2012-04-25 23:07:16
嘗試像這樣http://www.iphonedevsdk.com/forum/iphone-sdk-development/1269-sleep-equivalent-iphone.html以及只要你不在應用程序的代表 – arhimmel 2012-04-25 23:27:37