来自fb api的RequestDidLoad没有被调用

时间:2011-08-29 06:00:39

标签: xcode facebook-graph-api

我正在尝试下一期:

我有3个类从Facebook API获取数据并通过委托进行通信。第一堂课带我的朋友,然后每个朋友第二课打电话给朋友的事件,返回他们,然后为每个朋友的事件,第三课叫事件的ID以获得完整的事件信息。这是问题的来源,在调用第3类之后,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 {
....
}

1 个答案:

答案 0 :(得分:1)

假设此对象具有自己的委托。 您是否将Facebook的委托属性设置为控制器?

[facebook setDelegate:(id)self];

在.h文件的@interface

中实施代理
@interface myViewController : UIViewController <FacebookDelegate>

或类似的东西。

希望这有帮助!