Swift如何在标签

时间:2018-05-20 10:40:18

标签: swift label uilabel

第一张和第二张图片我可以成功读取和写入我的thisdata.txt文件,但我只能打印消息

我想让标签显示来自thisdata.text的文本

我该怎么做?

https://i.stack.imgur.com/E94df.png

https://i.stack.imgur.com/nntOL.png

https://i.stack.imgur.com/gOIiz.png

https://i.stack.imgur.com/Dznld.png

1 个答案:

答案 0 :(得分:1)

您需要将string分配给data标签。就像:

data.text = readString // If you need to print 'readString'
data.text = readStringProject // If you need to print 'readStringProject'
    var readString = ""
    do {
        readString = try String(contentsOfFile: fileURL)
        data.text = readString
    } catch let error as NSError {
        print("failed to read file")
        print(error)
    }