Adding a newline to a UITextView

微笑、不失礼 提交于 2019-12-25 03:06:14

问题


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



来源:https://stackoverflow.com/questions/1975494/adding-a-newline-to-a-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!