Citaat:
Oorspronkelijk geplaatst door JWVD
(Bericht 347913)
Maak een IBOutlet, koppel deze aan de UITextField en in je code is naamVanOutlet.text de waarde van het TextField
|
Nee okee dat snapte ik, waar ik mee zit, is hoe plaats ik deze in een link, ik heb 2 dingen geprobeerd:
1.
Code:
- (IBAction)submit {
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.timvanbeers.nl/script.php?naam=%@", [namefield text]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn)
{
NSLog(@"Gelukt!");
}
else
{
// inform the user that the download could not be made
NSLog(@"Mislukt!!");
}
}
dan krijg ik de error : Too many agruments to function 'URLWithString:'
2.
Code:
- (IBAction)submit {
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSString stringWithFormat:@"http://www.timvanbeers.nl/script.php?naam=%@",[namefield text]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn)
{
NSLog(@"Gelukt!");
}
else
{
// inform the user that the download could not be made
NSLog(@"Mislukt!!");
}
}
@end
Hier flipt de app als ik op Submit klik in mn app (die dus de IBAction aanroept)
met in de console:
Code:
[Session started at 2009-09-06 13:07:26 +0200.]
2009-09-06 13:07:26.531 Test[30638:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString absoluteURL]: unrecognized selector sent to instance 0xd42af0'
2009-09-06 13:07:26.532 Test[30638:20b] Stack: (
807902715,
2505109051,
808284155,
807854166,
807706786,
807437267,
6827990,
6526614,
6772078,
6779031,
10171,
814709201,
815110321,
815119058,
815114270,
814813151,
814722763,
814748641,
839148405,
807687520,
807683624,
839142449,
839142646,
814752238,
9252,
9106
)
IEMAND HELP?
Greetz
|