使用数组iOS SDK打开URL

时间:2013-02-25 13:42:29

标签: ios arrays nsurlconnection

我想在数组中打开一个URL,但它不起作用。这是我的代码:

NSArray *platformarray = [[NSArray alloc] initWithObjects:iphonestring,ipadstring,androidstring,blackberrystring, windowsstring,nil];


    NSString *url = [NSString stringWithFormat:@"http://xxx.nl/appofferte.php?hoedanigheid=%@&bedrijfsnaam=%@&naam=%@&email=%@&telefoon=%@&platformen=%@", hoedanigheid, bedrijf.text, naam.text, email.text, telefoon.text, platformarray];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

谁能帮我把数组放在1个变量中?

2 个答案:

答案 0 :(得分:0)

如果数组中的所有项都是字符串,那么您可以将它们与:

组合
NSString* combined = [platformarray componentsJoinedByString:@","];

答案 1 :(得分:0)

hoedanigheid=%@&bedrijfsnaam=%@&naam=%@&email=%@&telefoon=%@&platformen=%@", hoedanigheid, bedrijf.text, naam.text, email.text, telefoon.text, platformarray]; 

将platformarray更改为[platformarray objectAtIndex:thePlatformThatIWant];,例如:[platformarray objectAtIndex:0];

hoedanigheid=%@&bedrijfsnaam=%@&naam=%@&email=%@&telefoon=%@&platformen=%@", hoedanigheid, bedrijf.text, naam.text, email.text, telefoon.text, [platformarray objectAtIndex:thePlatformThatIWant]];