转载自:http://blog.youkuaiyun.com/pclass/article/details/6726964
I need to indicated a 'new line' in a string in an XML file I'm loading.
If I hard code the string:
- myTextView.text =[NSString stringWithString:@"Line1 \nLine2 \nLine3"];
It displays:Line1
Line2
Line3
(as expected)
But if I put the exact string in my XML file:
<someNodestring="Line1 \nLine2 \nLine3"/>And then load it into the UITableView it displays:
Line1\nLine2 \nLine3
原因是从XML中读取出来的"\n",系统认为是字符串,会默认转换为"\\n",所以当显示的时候就是字符串了,要想显示换行,需要自己手动将"\\n"转换为"\n",这样才能换行.
- NSString*b =[a stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
本文探讨了在iOS开发中,如何解决从XML文件加载到UITableView的文字内容中换行符不能正常显示的问题。通过字符串替换的方法,成功实现了换行。
1462

被折叠的 条评论
为什么被折叠?



