我建议创建一个名为 FacebookSingletonDelegate 的协议
@class FacebookSingleton;
@protocol FacebookSingletonDelegate <NSObject>
- (void) facebookSingletonDidLogin:(FacebookSingleton *) facebookSingleton;
- (void) facebookSingletonDidNotLogin:(FacebookSingleton *) facebookSingleton;
- (void) facebookSingletonDidLogout:(FacebookSingleton *) facebookSingleton;
- (void) facebookSingleton:(FacebookSingleton *)facebookSingleton
request:(FBRequest *) request
didLoad:(id)result;
@end
然后在您的 FacebookSingleton.h 中创建一个属性,例如
@property (nonatomic, strong) id<FacebookSingletonDelegate> delegate;
然后让您的视图控制器符合协议 -
@interface MyViewController<FacebookSingletonDelegate>
然后,将自己设置为视图控制器中的委托,例如 -
myViewController.delegate = self;
然后,从 FacebookSingleton 实现 (FacebookSingleton.m) 触发委托方法 -
- (void)request:(FBRequest *)request didLoad:(id)result
{
[self.delegate facebookSingleton:self request:request didLoad:result];
}
然后,您可以在视图控制器中实现以下方法 -
- (void) facebookSingleton:(FacebookSingleton *)facebookSingleton
request:(FBRequest *) request
didLoad:(id)result
{
// the view controller will receive the event in here
}