从 NSUserDefaults 获取数据时崩溃

发布于 2024-11-25 12:32:12 字数 944 浏览 1 评论 0原文

从 NSUSerDefaults 获取数据并传递使参数应用程序崩溃

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
   [loginController showView:[prefs objectForKey:kSavedUserName] :[prefs objectForKey:kSavedUserPassword]];
//              [loginController showView:@"[email protected]" Password:@"apple”];

当我在 NSLog [prefs objectForKey:kSavedUserPassword] 中打印这些值时显示值。密码和[prefs objectForKey:kSavedUserName] 用户名。

如果我硬编码我的需求参数,它就可以正常工作。

我的崩溃日志是

unrecognized selector sent to instance 0x5ccc2d0
2011-07-21 14:32:27.721 iShop[3815:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LoginViewController showView::]: unrecognized selector sent to instance 0x5ccc2d0'
*** Call stack at first throw:

Getting data from NSUSerDefaults and Passing has parameter application get crashed

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
   [loginController showView:[prefs objectForKey:kSavedUserName] :[prefs objectForKey:kSavedUserPassword]];
//              [loginController showView:@"[email protected]" Password:@"apple”];

When i am printing those value in NSLog [prefs objectForKey:kSavedUserPassword] is showing value. password and [prefs objectForKey:kSavedUserName] user name.

If I hard-coded my requirement parameters it working fine.

My crash log is

unrecognized selector sent to instance 0x5ccc2d0
2011-07-21 14:32:27.721 iShop[3815:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LoginViewController showView::]: unrecognized selector sent to instance 0x5ccc2d0'
*** Call stack at first throw:

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

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

发布评论

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

评论(2

您的 loginController 不响应 showView:: 消息,这就是您的应用崩溃的原因。检查LoginViewController中的方法名称,并更正它。我认为 NSUserDefaults 没有问题。
还要尽量避免选择器中未命名的参数,始终命名它们,以避免出现问题。

Your loginController doesn't respond to the showView:: message, that's why your app crashes. Check the method name in LoginViewController, and correct it. I think there is no matter with NSUserDefaults.
Also try to avoid unamed parameters in selectors, always name them, to avoid problems.

萌辣 2024-12-02 12:32:12

您注释掉的代码是正确的,因为它有第二个参数的名称。

[loginController showView:@"[email protected]" Password:@"apple”];

您的 NSUserDefaults 示例在选择器中省略了“密码”。尝试将其更改为

[loginController showView:[prefs objectForKey:kSavedUserName] Password:[prefs objectForKey:kSavedUserPassword]];

在更具风格的点上,我建议将方法名称更改为如下所示的名称。

showViewForUserName:(NSString*)user_name password:(NSString*)password;

Your commented out code is correct in that it has a name for the second parameter.

[loginController showView:@"[email protected]" Password:@"apple”];

Where your example with NSUserDefaults omits 'Password' from the selector. Try changing it to

[loginController showView:[prefs objectForKey:kSavedUserName] Password:[prefs objectForKey:kSavedUserPassword]];

On a more stylistic point I would suggest changing the method name to something more like below.

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