这里我可以使用NSUserDefaults
,但是我需要remove
这个NSUserDefaults
。
在我的应用程序中,我使用NSUserDefaults
来获取位置--一个View
到anotherView
,但是当我关闭我的应用程序时,我再次开始使用这些位置,这里我用于删除AppDeligate
中的位置
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"Location"];
}
但地点还在那里。
我怎么能移除这个?你能建议我。
发布于 2014-11-15 05:48:45
改变你的方法
- (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] synchronize];
https://stackoverflow.com/questions/26942963
复制相似问题