开发者

Crash upon getting data from NSUserDefaults

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:@"abcd03@gmail.com" 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:


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.


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

[loginController showView:@"abcd03@gmail.com" 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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜