swift 中的换行符识别

Line breaks recognition in swift

我制作了一个应用程序,可以通过网络服务从数据库调用数据,创建一个 XML 页面并解析它。之后它将 post WebView 中的文本但由于某种原因它无法识别换行符并且只是 post 忽略所有“\n”的文本。

有什么我遗漏的吗?

谢谢!

这是我向 WebView 添加文本的方式:

import UIKit


class PubViewController: UIViewController {


@IBOutlet weak var myWebView1: UIWebView!

var selectedFeedTitle = String()
var selectedFeedFeedContent = String()
var selectedFeedURL = String()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let feedContent:String! = "<h3>\(selectedFeedTitle)</h3>\(selectedFeedFeedContent)"
    myWebView1.loadHTMLString(feedContent, baseURL: nil)
}

HTML 中的换行符被忽略。您必须使用 <br/> 标签:

let feedContent:String! = "<h3>\(selectedFeedTitle)</h3>\(selectedFeedFeedContent)"
        .stringByReplacingOccurrencesOfString("\n", withString: "<br/>")