我需要在我的 iOS 应用程序中的 UITextView 中显示来自 JSON Webservice 的一些数据,该 UITextView 是多行的,但是当我在 TextView 上使用字符串时,新行不起作用。
这是我正在使用的代码:
// Data Value from JSON = testing the data value \r\n Another \n liine maybe?
NSString *responseDataString = [dictRequestorDetails objectForKey:@"data"];
txtWorkflowDetails.text = responseDataString;
当我执行此代码时,UITextField 显示
testing the data value \r\n Another \n liine maybe?
但是如果我输入类似的字符串
// 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 中起作用
最佳答案
刚刚关注了这篇文章:Adding a line break to a UITextView
我更新了 JSON feed 以输出新行,例如
testing the data value \nAnother \nmline maybe?
然后在我的代码中运行;
responseDataString = [responseDataString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
关于objective-c - iOS UITextView 忽略 JSON 响应中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13028861/