2012-10-23 74 views
1

我需要在UITextView中顯示一些JSON Webservice中的數據,這些數據是多行的,但是當我在textview上使用字符串時,新行不起作用。iOS UITextView忽略來自JSON響應的換行符

這裏是代碼我使用:

// Data Value from JSON = testing the data value \r\n Another \n liine maybe? 
NSString *responseDataString = [dictRequestorDetails objectForKey:@"data"]; 
txtWorkflowDetails.text = responseDataString; 

當我執行這個代碼的UITextField顯示

測試數據值\ r \ n另外\ n liine可能?

但是如果我在字符串中像

// Data Value from JSON = testing the data value \r\n Another \n liine maybe? 
NSString *responseDataString = [dictRequestorDetails objectForKey:@"data"]; 
txtWorkflowDetails.text = @"testing the data value \r\n Another \n liine maybe?"; 

鍵入換行符然後在TextView的工作

回答

3

只是跟着這個帖子:Adding a line break to a UITextView

我更新了我的JSON飼料產量新線如

測試數據值\ n另一個\ nmline也許?

然後在我的代碼中跑;

responseDataString = [responseDataString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"]; 
0

你可以先處理字符串,並將\ n

NSString *newString = [responseDataString stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]; 
0

是txtWorkflowDetails設置爲允許換行符(例如自動換行)替換\ n的所有出現?