从另一个类调用方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:@"xxx" andDelegate:self];
}
我在我的 AppViewDelegate
中声明了 Facebook。我想使用我的 UIViewController 或其他类中的 Facebook 类。我搜索了 sharedApplication
标题,但我没有搜索。
感谢您的回答。
- (BOOL)application:(UIApplication *)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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过以下方式获得它:
我将转换为 AppViewDelegate 假设这是您的 AppDelegate 的名称。然而,这样做的问题是,您通常不想从另一个类引用您的 AppDelegate 来将其用作保存全局变量的类。
在这种情况下我会做的是对 Facebook 类使用 Singleton 模式。检查此链接单例模式
It is possible to get it by doing:
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