这里我可以使用NSUserDefaults
,但是我需要移除
这个NSUserDefaults
。
在我的应用程序中,我使用 NSUserDefaults
获取位置 one View
到 anotherView
但是当我关闭我的应用程序时,这里会出现问题,并且我再次开始,位置仍然在那里,这里我用于删除 AppDeligate
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
}
但位置仍然存在。
我怎样才能删除它?
你能推荐我吗?
最佳答案
改变你的方法
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
进入
- (void)applicationWillTerminate:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
每当你在 NSUserDefaults
中删除或添加值时,不要忘记调用 [[NSUserDefaults standardUserDefaults] synchronize];
,如果你在那个时候获取值不需要添加 [[NSUserDefaults standardUserDefaults] 同步];
关于ios - 删除了 NSUserDefaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26942963/