如何从任何地方对applicationWillResignActive做出反应? [英] How to react to applicationWillResignActive from anywhere?

查看:141
本文介绍了如何从任何地方对applicationWillResignActive做出反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iphone应用程序的任何地方订阅applicationWillResignActive等活动的代码是什么?

What's the code to subscribe to an event like applicationWillResignActive in any place in your iphone application?

[更新]

让我重新解释一下我的问题。我不想在我的应用程序委托中对此做出响应,而是从另一个类中听取此事件。这是可能的还是我需要将事件从应用程序委托传递到相关类?

Let me rephrase my question. I don't want to respond to this in my application delegate, but rather listen to this event from another class. Is that possible or I need to pass the event from the application delegate to the concerning class?

推荐答案

看起来你在寻找这段代码。

Looks like you are looking for this code.

- (void) applicationWillResign {
    NSLog(@"About to lose focus");
}

- (void) myMethod { 
    [[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(applicationWillResign)
        name:UIApplicationWillResignActiveNotification 
        object:NULL];
}

这篇关于如何从任何地方对applicationWillResignActive做出反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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