2010-08-24 55 views
0

我想從繁重的用戶即名稱和位置處的兩個值,然後想將它們連接爲一個字符串,以產生輸出字符串如何連接兩個的UITextField值成一個字符串在iphone

IBOutlet UITextField *txtName; 
IBOutlet UITextField *txtLoc; 

要連接它們以產生下面的字符串。

學生姓名是txtName的和他是從txtLoc

基本上這就是我的完整代碼。

NSString *message = [NSString stringWithFormat:@"Student Name is %@ from %@ phone Number is%@ and he want to say%", txtName.text, txtLoc.text,txtPho.text,txtBody.text]; 



-(void) send:(id) sender { 
    [self sendEmailTo:@"[email protected]" withSubject:@"Contact for Quran Focus from iphone Application" withBody:message]; 

這就是我想要做的。 和EM收到錯誤

'txtName的' 不宣而這裏(不是在一個函數)

'txtLoc' 不宣而這裏(不是在一個函數) 'txtPho' 不宣而這裏(不是在一個函數) 「txtBody '這裏沒有聲明(不是功能)

雖然我已經正確地宣佈所有網點。

+0

concatenate - spelling :) – 2010-08-24 12:31:46

+0

@我的拼寫呃上帝保佑我...... :) – 2010-08-24 12:56:59

回答

1

您需要將您的消息分配行放在send:function函數中,就在調用sendEmailTo之前:withSubject:withBody :.

+0

hhahah我犯了一個錯誤。謝謝湯米 – 2010-08-25 07:56:41

6
NSString *result = [NSString stringWithFormat:@"Student Name is %@ and He is from %@", txtName.text, txtLoc.text]; 
+0

只有txtName.text,而不僅僅是txtName – Vladimir 2010-08-24 12:28:10

+0

是的,注意到第二張貼。 – 2010-08-24 12:29:56

+0

Thansk我已經這樣做了,但他們仍然得到這個錯誤......「'txtName'undeclared here(not in a function)」 – 2010-08-24 12:40:46

1
NSString *outputString=[NSString stringWithFormat:@"Student Name is %@ and he is from %@",txtName.text,txtLoc.text]; 
0

獲得從每個的UITextField([txtName的文本])的文本字符串,並使用stringByAppendingString方法:

combinedString = [[txtName的文本] stringByAppendingString:[txtLoc文本]]

相關問題