Objective c 将数据传递给AppDelegate
我想知道如何将数据传递回AppDelegate。假设我有这个计划Objective c 将数据传递给AppDelegate,objective-c,ios,delegates,Objective C,Ios,Delegates,我想知道如何将数据传递回AppDelegate。假设我有这个计划 AppDelegate - > RootViewController -> FirstViewController -> SecondViewController. SecondViewController具有在调用AppDelegate applicationWillTerminate方法时应保存的数据。我知道我可以使用singleton在应用程序中共享数据,但我不喜欢这种方法。在这种情况下,通知似乎不起作用
AppDelegate - > RootViewController -> FirstViewController -> SecondViewController.
SecondViewController具有在调用AppDelegate applicationWillTerminate方法时应保存的数据。我知道我可以使用singleton在应用程序中共享数据,但我不喜欢这种方法。在这种情况下,通知似乎不起作用
你能给我推荐什么吗?这应该会得到那个代表
AppDelegate * delegate =(AppDelegate*) [UIApplication sharedApplication].delegate
[delegate callSomeMethod:someData];
这应该得到那个委托
AppDelegate * delegate =(AppDelegate*) [UIApplication sharedApplication].delegate
[delegate callSomeMethod:someData];
给你的另一个建议。在AppDelegate.h类中,可以创建如下所示的类方法:
+ (AppDelegate *)getAppDelegate;
然后在AppDelegate.m中
+ (AppDelegate *)getAppDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
现在,您可以随时随地访问该委托(在导入AppDelagate.h之后)
一种更简洁的方法是创建一个类别并将代码放在那里
现在我的问题是:为什么需要在代理中保存数据?也许你可以用单身汉代替。有关更多信息,请参阅
希望对你有所帮助。还有其他建议。在AppDelegate.h类中,可以创建如下所示的类方法:
+ (AppDelegate *)getAppDelegate;
然后在AppDelegate.m中
+ (AppDelegate *)getAppDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
现在,您可以随时随地访问该委托(在导入AppDelagate.h之后)
一种更简洁的方法是创建一个类别并将代码放在那里
现在我的问题是:为什么需要在代理中保存数据?也许你可以用单身汉代替。有关更多信息,请参阅
希望有帮助。谢谢。我现在明白了。是否可以将数据直接传递给ApplicationIdentinterBackground?如果需要,可以在委托上调用该方法。但这样做似乎很奇怪。谢谢。我现在明白了。是否可以将数据直接传递给ApplicationIdentinterBackground?如果需要,可以在委托上调用该方法。但这似乎是一件奇怪的事情。