2011-08-02 16 views
5

也許一個簡單的問題,但我似乎無法得到它。我想獲取用戶個人資料圖片,但也希望搜索他/她的帖子。就像這樣:Multiple requestWithGraphPath Facebook iOS

[facebook requestWithGraphPath:@"me/picture?type=large" andDelegate:self]; 
[facebook requestWithGraphPath:@"me/home?q=TEST" andDelegate:self]; 

我可以得到picute了用下面的代碼:

- (void)request:(FBRequest*)request didLoad:(id)result{ 
    if ([result isKindOfClass:[NSData class]]) 
    { 

     UIImage *image = [[UIImage alloc] initWithData:result]; 
     UIImageView *profilePicture = [[UIImageView alloc] initWithImage:image]; 
     [image release]; 
     profilePicture.frame = CGRectMake(20, 20, 80, 80); 
     [self.view addSubview:profilePicture]; 
     [profilePicture release]; 

    } 
} 

但我不知道我能得到的搜索查詢數據出來。

任何幫助將是偉大的! Thnx

回答

14

requestWithGraphPath:andDelegate:返回一個指向FBRequest類型的對象的指針。保存並稍後使用它來區分request:didLoad:中的請求,並將其與傳遞給此方法的第一個參數進行比較。


例如,您可以有兩個屬性來容納請求對象。儘管如果你要處理很多請求,你可以使用像NSDictionary這樣的容器來代替。

self.pictureRequest = [facebook requestWithGraphPath:@"me/picture?type=large" andDelegate:self]; 
self.homeRequest = [facebook requestWithGraphPath:@"me/home?q=TEST" andDelegate:self]; 

然後在request:didLoad:

- (void)request:(FBRequest*)request didLoad:(id)result { 
    if (request == self.homeRequest) { 
     // ... 
    } else if (request == self.pictureRequest) { 
     // ... 
    } 
} 
+0

聽起來合乎邏輯,怎麼會有這樣的事情是什麼樣子? Thnx – Jos

+0

@Jos我更新了答案 – albertamg

+0

好的! thnx男人,這是要走的路! – Jos