NSLog on a NSString saved in a UITextfield
I'm trying to save a String from a textfield.
I have a
IBOutlet UITextField *login;
IBOutlet UITextField *pass;
...
@synthesize login,pass;
...
When I'm clicking to a button, this method is running :
- (IBAction) saveAuthentication: (id)sender {
//show an error message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login et Mot de passe" message:@"Votre login et votre mot de passe sont enregistrés."delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];[alert release];
//extr开发者_JAVA技巧act the login from the field and put in in Log
NSString *loginsaved = login.text;
NSString *passsaved = pass.text;
NSLog(@"%d", loginsaved );
//save the login and pass in the phone
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setObject:login.text forKey:@"login"];
[pref setObject:pass.text forKey:@"pass"];
}
When I execute it, The Console show me 0 instead of the login that I've typed...
a hundred of thanx for the help
Did you link the IBOutlets to the actual elements in Interface Builder?
Sounds like login could be nil, so login.text would return nil too.
For NSString
variable You should use below code...
NSString *loginsaved = login.text;
NSString *passsaved = pass.text;
NSLog(@"%@", loginsaved );
Here in objective
for Integer %d
, String %@
, Float %f
is used.
Keep smiling....
Try this instead:
NSLog(@"%@", loginsaved );
Yes it does because you use %d in your NSLog use %@ instead:
NSLog(@"%@", loginsaved );
精彩评论