开发者

Calling methods from another class

开发者 https://www.devze.com 2023-04-12 07:31 出处:网络
- (BOOL)application:(UIApplication开发者_JAVA百科 *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (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

精彩评论

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

关注公众号