-->

Adding a newline to a UITextView

2019-09-02 17:31发布

问题:

I've been searching for an answer to this question on google and some other forums, but I haven't found the answer yet. It seems like a simple enough question: how do I manually insert a newline into UITextView's text field?

If it matters, I'm reading my string from an SQLite database. That means that I'm translating a const char (I think - at least I've been casting it as such) into an NSString before I use it in UITextView's -setText. I've tried inserting '\n' into the SQLite database, but after everything is translated and assigned it comes back as '\n' on the iPhone screen. Is there another character I can use?

回答1:

Escape sequences in strings are interpreted at compile time and replaced with their actual byte value - therefore they have no meaning outside of the compiler.

Passing the string as it came out of your database to [UITextView setText:] is all you need to do. Your database should be holding line breaks as-is (0x0A).

Andrew