开发者

NSUSERDefaults class HAVE PROBLEM OR NOT?

开发者 https://www.devze.com 2023-01-02 07:21 出处:网络
NSString *string = @\"Hardwork\"; NSUserDefaults* defs111 = [NSUserDefaults standardUserDefaults]; [defs111 setObject:string forKey:@\"first_name_textfiel开发者_Go百科d\"];
NSString *string = @"Hardwork";
NSUserDefaults* defs111 = [NSUserDefaults standardUserDefaults]; 
[defs111 setObject:string forKey:@"first_name_textfiel开发者_Go百科d"]; 

Hi, In my code I'm unable to set this value string for key first_name_textfield. Why is it,so?


I have used this code to save and retrieve the values using NSUserDefaults. So refer this ,it will help you.

    IBOutlet UITextField * username;
    IBOutlet UITextField * password;

    NSString *userNameString;
    NSString *passWordString;  

    userNameString = [[NSString alloc] initWithFormat:[username text]];
    [username setText:userNameString];

    NSUserDefaults *usernamedefaults = [NSUserDefaults standardUserDefaults];
    [usernamedefaults setObject:userNameString forKey:@"StringKey"];

   passWordString = [[NSString alloc] initWithFormat:[password text]];
    [password setText:passWordString];

    NSUserDefaults *passworddefaults = [NSUserDefaults standardUserDefaults];
    [passworddefaults setObject:passWordString forKey:@"StringKey1"];

Thanks.

0

精彩评论

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