用下面的代碼我試圖用分頁讀取Instagram API內容。在FOR循環中,我打算調用方法loopData來獲取每個循環中都有一個新頁面標識的塊的內容。用於分頁的塊循環
...
for (int a = 1; a <= 3; a++)
{
NSLog(@"Loop count: %i", a);
[self loopData];
}
-(void)loopData
{
NSString *next;
next = [Globals sharedGlobalData].nextMaxId;
[client getUserMedia:[userTextField stringValue]
count:kCount
minId:-1
maxId:next
success:^(NSArray *media) {
[textView setString:[media description]];
NSLog(@"Next_Max_Id: %@ ", [Globals sharedGlobalData].nextMaxId);
}
failure:^(NSError *error, NSInteger statusCode) {
[self logError:@"media" error:error statusCode:statusCode];
}
];
}
我的問題是,該塊運行你的時間,而不是在每一個循環週期。該塊在for循環完成後運行。因此新的頁面ID不能傳遞給塊。
日誌看起來是這樣的: 迴路1 迴路2 環3
閱讀內容通過大宗 閱讀內容通過大宗 閱讀內容通過大宗
許多感謝的想法! getUserMedia
// Get a user's media
- (void)getUserMedia:(NSString*)userId // Can be 'self' for the current user
count:(int)count
minId:(int)minId // -1 for start
maxId:(int)maxId // -1 for no upper limit
success:(void (^)(NSArray* media))success
failure:(void (^)(NSError* error, NSInteger statusCode))failure {
// Setup the parameters
NSMutableDictionary* parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:count], @"count", nil];
if (minId > 0) [parameters setObject:[NSNumber numberWithInt:minId] forKey:@"minId"];
if (maxId > 0) [parameters setObject:[NSNumber numberWithInt:maxId] forKey:@"maxId"];
// Fire the get request
[self getPath:[NSString stringWithFormat:@"users/%@/media/recent", userId]
modelClass:[InstagramMedia class]
parameters:parameters
collection:success
single:nil
failure:failure];
}
我期望任何採取成功或失敗塊來異步執行它們。 'getUserMedia:count:minId:maxId:success:failure:'看起來像什麼? –
@CarlVeazey我試圖使用Instagram包裝[鏈接](github.com/stuartkhall/instagram),我發佈了上面的getUserMedia的實現。謝謝! – techcharger