从 NSUserDefaults 获取数据时崩溃
从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
loginController
不响应showView::
消息,这就是您的应用崩溃的原因。检查LoginViewController
中的方法名称,并更正它。我认为NSUserDefaults
没有问题。还要尽量避免选择器中未命名的参数,始终命名它们,以避免出现问题。
Your
loginController
doesn't respond to theshowView::
message, that's why your app crashes. Check the method name inLoginViewController
, and correct it. I think there is no matter withNSUserDefaults
.Also try to avoid unamed parameters in selectors, always name them, to avoid problems.
您注释掉的代码是正确的,因为它有第二个参数的名称。
您的 NSUserDefaults 示例在选择器中省略了“密码”。尝试将其更改为
在更具风格的点上,我建议将方法名称更改为如下所示的名称。
Your commented out code is correct in that it has a name for the second parameter.
Where your example with NSUserDefaults omits 'Password' from the selector. Try changing it to
On a more stylistic point I would suggest changing the method name to something more like below.