NSUserDefaults 给出错误

发布于 2024-12-11 08:30:19 字数 373 浏览 0 评论 0原文

我在我的应用程序中使用 NSUserDefaults 。它工作正常,直到我有 ios 4.3 和 xcode 4.0。但现在我已经更新到 ios 5 和 xcode 4.2...

它给出了错误!

NSString *storedLanguage = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];


*** -[NSUserDefaults objectForKey:]: message sent to deallocated instance 0x26e800

我不知道如何解决它..我已经尽力了!

任何帮助将不胜感激!

谢谢

I am using NSUserDefaults in my application. It was working fine until i was having ios 4.3 and xcode 4.0. But now i have updated to ios 5 and xcode 4.2...

It's giving error!

NSString *storedLanguage = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];


*** -[NSUserDefaults objectForKey:]: message sent to deallocated instance 0x26e800

I don't know how to resolve it..i have tried all my effort!

Any help will be appreciated!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

允世 2024-12-18 08:30:19

从你的问题来看,它看起来像是某个对象的早期发布。
说不出问题出在哪里。
但尝试一下这个

NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] retain];
NSString * storedLanguage = [NSString stringWithFormat:@"%@",[defaults objectForKey:@"language"]];
[defaults release];

================================= 或 =========== =====================
这个

NSString *sessionId=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"language"]];

他们可能会帮助你......

干杯

Well from your question its looking like early release of some object.
Cant say where is the problem.
But give a try to this one

NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] retain];
NSString * storedLanguage = [NSString stringWithFormat:@"%@",[defaults objectForKey:@"language"]];
[defaults release];

=============================== OR ================================
This one

NSString *sessionId=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"language"]];

They might help you...

Cheers

离笑几人歌 2024-12-18 08:30:19

请执行 Naved 所说的相同操作,但稍加修改。

NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] retain];
NSString * storedLanguage = [defaults objectForKey:@"language"];
[defaults release];

Please do the same thing said by Naved but with little modification.

NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] retain];
NSString * storedLanguage = [defaults objectForKey:@"language"];
[defaults release];
别在捏我脸啦 2024-12-18 08:30:19

对您的设置使用不与保留(现有但不可访问)设置名称冲突的不同键。 (例如“MyUsersLanguageSettingsKey”)

Use a different key for your settings that doesn't collide with reserved (existing but inaccessible) setting names. (e.g. "MyUsersLanguageSettingsKey")

岁月静好 2024-12-18 08:30:19

现在工作正常了..实际上ios5中有一个东西。如果您在一个类中释放 nsdefaults,则无法在应用程序中的任何位置使用。

我在 appdelegate 文件中释放了 NSDefaults。所以它在其他类中不起作用..但它在ios4中工作..我不知道为什么它在这里工作?

感谢大家抽出时间!!

It's working fine now.. Actually there is one thing in ios5. If you release your nsdefaults in one class, you can't use anywhere in the application..

I was releasing the NSDefaults in my appdelegate file. so it was not working in other classes..But it was working in ios4.. I don't know why it was working here?

Thanks to all for giving time!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文