开发者

Calling methods from another class

- (BOOL)application:(UIApplication开发者_JAVA百科 *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions
{
  facebook = [[Facebook alloc] initWithAppId:@"xxx" andDelegate:self];
}

I declared Facebook in my AppViewDelegate. I want use this Facebook class from my UIViewController or another class. I searched sharedApplication title but i didn't that.

Thanks for your answer.


It is possible to get it by doing:

[(AppViewDelegate *)[[UIApplication sharedApplication] delegate] facebook];

I put the cast to AppViewDelegate assuming that is the name of your AppDelegate. However, the problem with this is that you normally don't want to reference your AppDelegate from another class to use it as a class that holds a global variable.

What I would do in this situation is to use a Singleton pattern for Facebook class. Check this link Singleton Pattern

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜