2011-12-25 63 views
0

我试图保存viewController中的数据。我正在通过使用appDelegate中的委托方法来做到这一点:- (void)applicationDidEnterBackground:(UIApplication *)application如何在使用故事板时获取appDelegate中的viewController指针

问题是,当使用故事板时,viewControllers会自动为您设置,我不知道如何获得指向它们的指针,这样我可以访问他们的数据进行保存。

如何在使用故事板时在appDelegate中获取指向他们的指针?

回答

1

您可以在UIViewController的内部注册接收往返通知,并在那里管理储存。

//Going into background 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveData) name:@"UIApplicationDidEnterBackgroundNotification" object:nil]; 

//Waking up 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingOnWakeup) name:@"UIApplicationWillEnterForegroundNotification" object:nil]; 
相关问题