2

I need to display some data from a JSON Webservice in my iOS App inside a UITextView which is multiline however when I use the String on the textview the new lines do not work.

Here is the code I am using:

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

When I execute this code the UITextField shows

testing the data value \r\n Another \n liine maybe?

However If I type in the string like

// 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?";

The line breaks then work in the TextView

MonkeyBlue
  • 2,234
  • 6
  • 31
  • 41

4 Answers4

3

Just followed this post: Adding a line break to a UITextView

I updated my JSON feed to output the new lines like

testing the data value \nAnother \nmline maybe?

And then in my code ran;

responseDataString = [responseDataString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
Community
  • 1
  • 1
MonkeyBlue
  • 2,234
  • 6
  • 31
  • 41
1

Swift 4:

let stringForUITextView = originJsonString.replacingOccurrences(of: "\\n", with: "\n")
Serhii Didanov
  • 2,200
  • 1
  • 16
  • 31
0

You can process the string first and replace all occurrences of \n with \n

NSString *newString = [responseDataString stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
Sumit Mundra
  • 3,891
  • 16
  • 29
0

Is txtWorkflowDetails set to allow Line Breaks (e.g. Word Wrap)?

ApplinguaRob
  • 304
  • 3
  • 7