向UITextView添加换行符

向UITextView添加换行符

本文介绍了向UITextView添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Google和其他一些论坛上寻找此问题的答案,但是我还没有找到答案.似乎很简单的问题:如何在UITextView的文本字段中手动插入换行符?

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?

如果有关系,我正在从SQLite数据库中读取我的字符串.这意味着我将const char(我认为-至少我一直在将其转换为此类)转换为NSString,然后再在UITextView的-setText中使用它.我曾尝试在SQLite数据库中插入"\ n",但是在翻译并分配了所有内容之后,它在iPhone屏幕上又显示为"\ n".我可以使用另一个字符吗?

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?

推荐答案

字符串的转义序列在编译时进行解释,并用其实际字节值替换-因此,它们在编译器之外没有任何意义.

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.

将需要将字符串从数据库中传递出来的字符串传递给[UITextView setText:].您的数据库应按原样保留换行符(0x0A).

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).

安德鲁

这篇关于向UITextView添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 04:35