Reputation: 4551
i have two UItextFields, userNameTextField and passwordTextField and a UIbutton connection. I would like to have what the user typed in the userNametextField and the passwordTextField, How i can do this please ?? thanks for your answer.
#pragma mark - User auhtentification
-(IBAction)userAuthentificate{
BOOL loginValid = YES;
BOOL passwordValid = YES; // Not specified yet
// contrioll d'interfac__ on test login et password
if (loginValid && passwordValid) {
NSString *jsonRequest = @"{\"login\":\"Samir\",\"password\":\"test\",\"mail\":\"[email protected]\"}";
// NSString *jsonRequest = @"{\"login\":\"Samir\",\"password\":\"test\",\"mail\":\"[email protected]\",\"editor\":\"1\"}";
NSString *request_url =@"http:.../register"; // Url WS
NSURL *url = [NSURL URLWithString:request_url];
self.currentRequest = [ASIFormDataRequest requestWithURL:url];
currentRequest.delegate =self;
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[self.currentRequest appendPostData:requestData];
[self.currentRequest setRequestMethod:@"POST"];
[self.currentRequest startSynchronous];
}
}
Upvotes: 0
Views: 315
Reputation: 12890
How about a simple string replacement?
NSString *jsonRequest = [NSString stringWithFormat:@"{\"login\":\"%@\",\"password\":\"%@\",\"mail\":\"%@\"}", userNameTextField.text, passwordTextField.text, emailtextField.text];
Upvotes: 1
Reputation: 8147
You can put something like this in the place of your jsonRequest
string (the code uses the SBJson framework):
NSDictionary *container = [[NSDictionary alloc] initWithObjectsAndKeys:
[loginTextField text], @"login",
[passwordTextField text], @"password",
[mailTextField text], @"mail"];
NSString *jsonString = [container JSONRepresentation];
// don't forget to release container if not using ARC AFTER creating the NSData object
Upvotes: 2
Reputation: 39978
Use
NSString *jsonRequest = [NSString stringWithFormat:@"{\"login\":\""%@"\",\"password\":\""%@"\",\"mail\":\"[email protected]\"}",userNameTextField.text,passwordTextField.text];
Upvotes: 0