view controller variables in ApplicationWillResignActive

五迷三道 提交于 2019-12-09 04:52:26

You are going about this all wrong. There is no need to do any of this in the app delegate.

Have each view controller listen for the UIApplicationWillResignActiveNotification notification. Then each view controller can do whatever it feels is appropriate to save its data when the notification is received.

Update:

In the view controller's init... method, register for the notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resigningActive) name:UIApplicationWillResignActiveNotification object:nil];

In the view controller's dealloc method, unregister:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
}

Then implement the resigningActive method:

- (void)resigningActive {
    // The app is resigning active - do whatever this view controller needs to do
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!