不确定在使用故事板时如何正确地子类化UIApplication [英] Not sure how to properly subclass UIApplication while using storyboards

查看:521
本文介绍了不确定在使用故事板时如何正确地子类化UIApplication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户不活动的X时间之后返回我的故事板的初始viewcontroller(没有触发事件触发)。经过一些研究后,我发现检测不活动的最常见方法是触发NSTimer并在事件触发时重置间隔。为了检测已触发的事件,我们在UIApplication的子类中覆盖[UIApplication sentEvent:]。这就是我陷入困境的部分。

I want to return to my storyboard's initial viewcontroller after X time of user inactivity (no touch events fired). After some research I see that the most common way of detecting inactivity is to fire an NSTimer and reset the interval when an event is fired. To detect a fired event, we override [UIApplication sentEvent:] in a subclass of UIApplication. This is the part where I'm kind of stuck.

我正在看这个项目作为参考

I'm looking at this project as reference

http://www.icodeblog .com / 2011/09/19 / time-out-an-application-due-to-inactivity /

https://github.com/elc/ELCUIApplication

我不确定如何在使用故事板时实现类似的功能。我尝试了类似于github projet的东西;我创建了一个新类,它是UIApplication的子类,覆盖了所需的方法,最后更改了main函数中的目标类(从我的appdelegate到子类UIApplication的新类)。通过这样做我得到以下错误

I'm not sure how to implement a similar functionality when working with storyboards. I tried something similar to that github projet; I created a new class that was a subclass of UIApplication, overrode the needed method and finally changed the targeted class in the main function (from my appdelegate to the new class that subclassed UIApplication). By doing so I got the following error

如果想要使用主故事板文件,则应用委托必须实现窗口属性。

github中的appDelegate是NSObject的子类,并根据我的理解手动加载其窗口属性中的初始视图,而我的appDelegate是UIResponder的子类,它本身就是UIApplication的超类。我不知道如何继续,我已经在我的AppDelegate中有窗口属性并合成,但我不知道该怎么做。

The appDelegate in the github is a subclass of NSObject and manually loads up the initial view in his window property from what I understand, while my appDelegate is a subclass of UIResponder which itself is a superclass of UIApplication. I'm not sure how to proceed, I already have the window property in my AppDelegate and synthesized, but I'm not sure what to do with it.

任何帮助都将不胜感激!

Any help would be greatly appreciated!

推荐答案

听起来像您将错误的参数更改为 UIApplicationMain

It sounds like you changed the wrong argument to UIApplicationMain.

默认调用 UIApplicationMain 看起来像这样:

The default call to UIApplicationMain looks like this:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

第三个参数(默认为 nil )是要使用的 UIApplication 类的名称。如果它是零,则应用程序只使用 UIApplication

The third argument (nil by default) is the name of the UIApplication class to use. If it's nil, the app just uses UIApplication.

第四个参数是<$ c $的名称c> UIApplicationDelegate 要使用的类。

The fourth argument is the name of the UIApplicationDelegate class to use.

听起来你改变了第四个参数,但你应该改变了第三个参数:

It sounds like you changed the fourth argument, but you should have changed the third argument:

return UIApplicationMain(argc, argv,
    NSStringFromClass([MyApplication class]),
    NSStringFromClass([AppDelegate class]));

这篇关于不确定在使用故事板时如何正确地子类化UIApplication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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