2014-02-16 62 views
-3

我正在学习如何编写iOS应用程序并正在学习Objective-C。我试图采取一个有7个字段的表单并将其发布到我的网络服务器。我已经有了不张贴代码,我只需要所有的文本输入字段连接成一个NSString在iOS中发布表单数据

文本输入字段在.h文件命名如下:

ctName
ctAddress1
ctAddress2
ctCity
ctState
ctZIP ctPhone

任何帮助将是非常赞赏。

UPDATE

所以,我已经想通了,但我不能回答我的问题了几个小时......这是我想出了。这可能不是最有效的方式,但我已经测试过它并且工作正常。

NSString *body  = [NSString stringWithFormat:@"stripeToken=%@", token.tokenId]; 
body = [body stringByAppendingString:@"&ctname="]; 
body = [body stringByAppendingString:self.ctName.text]; 
body = [body stringByAppendingString:@"&ctadd1="]; 
body = [body stringByAppendingString:self.ctAddress1.text]; 
body = [body stringByAppendingString:@"&ctadd2="]; 
body = [body stringByAppendingString:self.ctAddress2.text]; 
body = [body stringByAppendingString:@"&ctcity="]; 
body = [body stringByAppendingString:self.ctCity.text]; 
body = [body stringByAppendingString:@"&ctstate="]; 
body = [body stringByAppendingString:self.ctState.text]; 
body = [body stringByAppendingString:@"&ctzip="]; 
body = [body stringByAppendingString:self.ctZIP.text]; 
body = [body stringByAppendingString:@"&ctphone="]; 
body = [body stringByAppendingString:self.ctPhone.text]; 
+1

由于问题是在串联看看:http://stackoverflow.com/questions/8853865/simple-string-concatenation-in-objective-c –

回答

-1

试试这个

NSString completeString = [NSString stringWithFormat:@"%@_%@_%@_%@_%@_%@_%@",_ctName,_ctAddress1,_ctAddress2,_ctCity,_ctState,_ctZIP,_ctPhone]; 

通知所有的变量有一个下划线(_)作为前缀。对于这项工作,确保您的休息syntethize每一个人他们在.M这样

@syntethize ctName, ctAddress1, ... 

等。

如果您正在使用故事板,请验证所有变量是否正确链接。

+0

我忘了:我在stringWithFormat中添加了下划线作为标记。这样,你可以使用(_)作为参数来拆分它,并且你将再次拥有所有的变形变量。当然,您可以将该标记更改为您的偏好 –