你好,我没有太多的编程经验,我想在用户离开应用程序时调用一个方法。我知道我将使用应用程序委托(delegate)方法 applicationDidEnterBackground
,但我如何使该调用成为我的 ViewController
类中的方法?
非常感谢您的帮助!
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <ADBannerViewDelegate>
{
//Images and buttons
}
-(void)stop;
@end
最佳答案
您可以在此处使用通知。在 viewController 的 viewDidLoad 中为此通知创建一个监听器,并将函数分配给它。 例如:
在您的 View Controller 中,在 viewDidLoad 中添加以下内容
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationEnabled) name:UIApplicationDidEnterBackgroundNotification object:nil];
关于ios - Xcode 5,当用户离开应用程序时如何调用方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21980542/