ios - 删除了 NSUserDefaults

标签 ios objective-c nsuserdefaults

这里我可以使用NSUserDefaults,但是我需要移除这个NSUserDefaults
在我的应用程序中,我使用 NSUserDefaults 获取位置 one ViewanotherView 但是当我关闭我的应用程序时,这里会出现问题,并且我再次开始,位置仍然在那里,这里我用于删除 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/

相关文章:

javascript - React Native 中的后备字体

ios - 在 Xcode 4.1 中使用 Three20 时出现大量问题

ios - indexPathForSelectedRow() 的问题,返回不正确的索引。使用 swift

iphone - 在Appstore中更新应用程序后,NSUserDefaults值和SQLite数据库

ios - 在 iPhone 和 iPad 中标签和 SpanLabel 没有正确对齐(略有不同)

ios - 如何在 iOS 上进行 base64 编码?

objective-c - 不断替换数组中的对象是否存在任何问题?

ios - 调整 UITextfield 宽度

ios - 如何使用 NSTimer 使 UICollectionView 自动滚动?

iphone - 知道上次使用该应用程序的时间,iPhone应用程序