2011-08-29 52 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