我无法显示Textfile.txt中的文本。我能够在控制台上成功打印数据,但无法在UITextView上打印。谢谢
@IBOutlet weak var mytextview: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let path = "/Users/jack/textfile.txt"
do {
var data = try NSString(contentsOfFile: path,
encoding: String.Encoding.ascii.rawValue)
print(data)
}catch {
//handle error
print(error)
}
mytextview.text = Data() as? String
}
答案 0 :(得分:0)
您可以尝试
setRequestHeader
答案 1 :(得分:-1)
尝试一下:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let path = "/Users/jack/textfile.txt"
do {
var data = try NSString(contentsOfFile: path,
encoding: String.Encoding.ascii.rawValue)
mytextview.text = data // change here
print(data)
}catch {
//handle error
print(error)
}
mytextview.text = Data() as? String
}