2011-08-29 74 views
0

我experiancing下一個問題:RequestDidLoad不會被調用

我有3類,從Facebook的API獲取數據,並通過委派進行通信。第一堂課帶我的朋友,然後爲每個朋友第二堂課調用朋友的活動,返回他們,然後爲每個朋友的活動,第三類調用活動的ID來獲得完整的活動信息。這是問題出現的地方,在調用3rd類之後,fb請求api得到執行(requestLoading函數開始),但它不會在該類中等待得到答覆,而是跳出該類。

下面是代碼:

// Class 1: 
// calling friends in first class 
- (void) callFriendData 
{ 
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate]; 
Facebook *facebook = appDelegate.facebook; 
[facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 
} 

// receiving friends + calling friend class for each friend in which we will call events 
- (void)request:(FBRequest *)request didLoad:(id)result { 
NSMutableArray *data = [result objectForKey:@"data"]; 
NSMutableArray *tmpFriendID = [data valueForKey:@"id"]; 
NSMutableArray *tmpFriendName = [data valueForKey:@"name"]; 
for(int i=0;i<[tmpFriendID count];i++) 
{ 
    FBFriend *fbFriend = [[FBFriend alloc]init]; 
    [fbFriend setDelegate:self]; 
    fbFriend.friendID = [tmpFriendID objectAtIndex:i]; 
    fbFriend.friendName = [tmpFriendName objectAtIndex:i]; 
    [fbFriend takeEvents]; 

    [friendDataArray addObject:fbFriend]; 
    [fbFriend release]; 
} 
} 

// class 2, friend, here I call events 

- (void) takeEvents 
{ 
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate]; 
Facebook *facebook = appDelegate.facebook; 
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/events",self.friendID] andDelegate:self]; 
} 

// receiving events for certain user 
- (void)request:(FBRequest *)request didLoad:(id)result { 
.... 

// sending events back to 1st class 
[[self delegate] eventsTaken:eventIDs fromFriendID:self.friendID]; 
} 

// first class receives events for certain user, saves it to array of 
//user's events and then calls 3rd class for each event in array, to get full info 
- (void) eventsTaken: (NSArray *)idEvents fromFriendID: (NSString*) idFrenda 
{ 

for(int i=0;i<[friendDataArray count];i++) 
    if([[[friendDataArray objectAtIndex:i] valueForKey:@"friendID"] isEqual:idFrenda]) 
     for(int j=0;j<[idEvents count];j++) 
     { 
      Event *event = [[Event alloc] init]; 
      event.eventID=[idEvents objectAtIndex:j]; 
      [event takeEvent]; 

      [event release]; 
     } 
} 

// 3rd class, event 
-(void) takeEvent 
{ 
PicShowAppDelegate* appDelegate = (PicShowAppDelegate*)[[UIApplication sharedApplication] delegate]; 
Facebook *facebook = appDelegate.facebook; 
[facebook requestWithGraphPath:[NSString stringWithFormat:@"%@",self.eventID] andDelegate:self]; 

} 

// this never gets called 
- (void)request:(FBRequest *)request didLoad:(id)result { 
.... 
} 
+0

沒有線索,任何人? – kikovi

回答

1

只是假設這個對象有自己的代表。 您是否將Facebook的委託屬性設置爲您的控制器?

[facebook setDelegate:(id)self];

還實現委託,在您的.h文件中的依稀相似@interface

@interface myViewController : UIViewController <FacebookDelegate> 

什麼的。

希望這會有所幫助!

+0

您好,感謝您嘗試幫助和創建帖子。 :)我不確定你是否完全理解這個問題。在這裏沒有viewController,在代碼中,評論分隔3個不同的類(friendData稱爲朋友,fbFriend稱爲朋友的事件,最後是獲取每個事件的完整信息的類事件)。 [facebook requestWithGraphPath:@「..」andDelegate:self];通過這和Delegate:自我(至少我認爲)我們設置代表。所以自我意味着數據應該返回到調用類。在調用類中,函數requestDidLoad被實現,所以數據應該來.. – kikovi

+0

但是在我的程序數據中沒有到達。它說requestLoading 1000次,然後走出課程事件..:/是的,所有的類都實現了協議。 :) – kikovi

+0

你需要以某種方式驗證Facebook嗎?並且您正在驗證的位置(例如網站)是否正確? ( – Craimasjien