2012-10-23 27 views
0

是否可以將地址的所有行添加到文本視圖中,到目前爲止,我只能將最後一行顯示在視圖adresslines中。是否可以將地址線從聯繫人添加到文本視圖

self.adresslines.text = (NSString *)(CFDictionaryGetValue(dictionary, kABPersonAddressCityKey)); 
     self.adresslines.text = (NSString *)(CFDictionaryGetValue(dictionary, kABPersonAddressStreetKey)); 
     self.adresslines.text = (NSString *) (CFDictionaryGetValue(dictionary, kABPersonAddressZIPKey)); 

回答

1

就像你現在正在設置文本視圖的文本和地址的每一行一樣。你想追加,而不是替換。像這樣將工作:

NSMutableString *text = [NSMutableString string];  
[text appendString:(NSString *)(CFDictionaryGetValue(dictionary, kABPersonAddressCityKey))]; 
[text appendString:@"\n"]; 
[text appendString:(NSString *)(CFDictionaryGetValue(dictionary, kABPersonAddressStreetKey))]; 
[text appendString:@"\n"]; 
[text appendString:(NSString *) (CFDictionaryGetValue(dictionary, kABPersonAddressZIPKey))]; 
self.addresslines.text = text; 

當然你也可以在這裏添加檢查,以避免空行或根據需要添加其他格式。

+0

作品魅力!謝謝,我現在可以學習,謝謝你的解釋。 – JSA986

相關問題