AppDelegate 到 UIViewController [英] AppDelegate to UIViewController

查看:21
本文介绍了AppDelegate 到 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有标头和实现文件以及两个 appDelegate 文件的示例代码.我想将项目的功能添加到我的应用程序中.前两个文件是一个ViewController文件,所以我只需要把它拖进去,但另外两个是AppDelegate,而且我显然不能有两个应用程序委托.但是在这个示例应用程序的情况下,应用程序委托被用作适当的视图控制器,因为在 UIViewController 文件的 .m 文件中,有这样的代码:

I have a sample code with a header and an implementation file and the two appDelegate files. I would like to add what the project does to my app. The first two files are a ViewController file, so I just need to drag it in, but the other two are AppDelegate, and I obviously can't have two app delegates. But in the case of this sample app the app delegate is used as a proper viewcontroller, because in the .m file of the UIViewController file, there is this code:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

由于 AppDelegate 没有实现 applicationWillBecomeActive: 等方法,我该如何将文件转换为 UIViewController 文件?我需要在上面的代码中更改什么才能调用控制器而不是委托(我的 AppDelegate 将保持不变).

Since the AppDelegate doesn't implement methods such as applicationWillBecomeActive:, how can I transform the file into a UIViewController file? What do I need to change in the code above to call the controller, instead of the Delegate (my AppDelegate will so remain untouched).

代码位于 GitHub

这就是我所做的(代码需要包含 Facebook API).转到下载选项卡并下载 Archive.zip 和 AppDelegate.zip:https://github.com/Alexmitico45/Facebook 请求/下载

This is what I have done (the code needs the Facebook API to be included). Go on the download tab and download Archive.zip and AppDelegate.zip: https://github.com/Alexmitico45/FacebookRequests/downloads

基本上控制器 ContactFBSViewController 链接到故事板中的一个视图控制器.

Basically the controller ContactFBSViewController is linked the a viewcontroller in the storyboard.

推荐答案

我解决了这个问题.我必须做的是使视图控制器成为单例:

I solved the problem. What I had to do is make the viewcontroller a singleton:

+ (FacebookViewController *) sharedManager;

..然后使用此代码访问它:

..then use this code to access it:

FacebookManager *manager = [FacebookManager sharedManager];

经过几天的反复试验,它终于奏效了!!

And after days of trial and error it finally works!!

这篇关于AppDelegate 到 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆