2012-06-05 44 views
0

查看开始iOS 5中的示例以保持您的应用程序状态,在为应用程序显示的第一个viewController中,它们在viewDidLoad:中注册applicationWillResignActive。这对我来说很有意义,因为您在显示第一个视图时注册了该通知。在哪里注册applicationWillResignActive使用UIStoryboard

我很困惑你是否总是这样做,或者你通常在哪里注册这个通知。 Q1)像他们在这个viewController注册这个通知,以便他们可以重新创建此视图? Q2)如果是这样,我是否为每个viewController执行此操作?

Q3)我使用UIStoryboard和我的第一个viewController是一个UITabBarController。那么,我要在第一个标签的viewController中注册通知吗?

我还有一个单独的DataManager对象,用于保存应用程序的数据,如果这有助于任何人指导我以正确的方向保存数据。谢谢!

回答

0

这些方法都在AppDelegate.m

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    /* 
    Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    */ 
} 

你可以在这里进行自己的行为。然而,你可以注册在另一个视图控制器中“侦听”该事件(就像你的例子),但这只是为了更容易地将该事件通知发送到该视图控制器。

1)不,只是为了确保当这个VC被加载时它将能够听到这个事件。

2)不,只为那些你想要通过的人很容易就这样。然而,使用appdelegate.m和每个vc视图确实显得更好。 3)取决于你想要保存的数据类型,但通常你创建你自己的文件,并像其他操作系统一样将它保存到磁盘。 ios可让您访问应用程序的“文档”文件夹,并且每个文件夹都用于特定的内容,请阅读文档。

相关问题