来自Objective-C的主类的调用方法 [英] Calling method from principal class in objective-C

查看:36
本文介绍了来自Objective-C的主类的调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在10分钟内无法触摸屏幕,那么我就完成了超时功能,然后我的应用程序直接进入了登录屏幕.对于上述问题,我从此处使用示例代码关联.在该链接中,我遵循@Brian King的建议.我创建了自己的自定义 UIWindow 类,并将所有超时代码设置为他给定的Github链接代码.

现在,我的应用设计师是我将rootviewcontroller放在自定义UIWindow类上,然后显示我的自定义警报视图,并在警报视图按钮上编写超时/继续计时器功能.注意:-按照给苹果提供的UIResponder链,每次触摸都将其称为超级视图,最后调用UIWindow.

I'm did functionality of timer out if User can't touch on screen for 10 minutes then my application directly goes on login screen. For above problem i use sample code from here https://github.com/B-Sides/ELCUIApplication doing some changes in naming of class so my class is PB_TIMER_UIApplication instead of ELCUIApplication. I calling PB_TIMER_UIApplication class in main.m class it implementation as following,

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

I set principalClassName as a PB_TIMER_UIApplication

Now i create one property and instance method in PB_TIMER_UIApplication like following,

@interface PB_TIMER_UIApplication :  UIApplication{
    NSTimer *_idleTimer;
}
@property(nonatomic) int timerTimeOutIntervals;

- (void)resetIdleTimer;

Now i want my application show alert before going login screen/timeout session. If alert button press OK then my timer again start for 10 second. That why i create an property for timerTimeOutIntervals and that property and resetIdleTimer instance method i want to call in throughout application. So i trying to access property/method as like Appdelegate call, [[PB_TIMER_UIApplication sharedApplication] setTimerTimeOutIntervals:10]; but it show me static error ,

My question where i'm wrong and what to do for calling property of instance method from principle class?

解决方案

Yes i solve my problem. I changed my architecture of application firstly i create subclass of UIApplication and and set it as a principle class in main.m file. Due to this my UIApplication subclass run first then main UIApplication where UIApplicationDelegate are set. And that why i unable declare launching timeout intervals, my app goes in recursion.

After searching i got this link. I follow suggestion of @Brian King in that link. I create my own custom UIWindow class and put up all timeout code as his given Github link code.

Now my app architect is i put my rootviewcontroller on my custom UIWindow class, then show my custom alert view and write timeout/continue timer functionality on alert view buttons. Note :- As per apple doc given UIResponder chain every touch calling it superview and finally call UIWindow.

这篇关于来自Objective-C的主类的调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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