【问题标题】:Add text to textview in Swift在 Swift 中将文本添加到 textview
【发布时间】:2015-01-14 02:25:25
【问题描述】:

如何将文本添加到标签或表格视图,而不是更新标签/表格视图?

var personArray: [Person] = [
Person(name: "Heine", sex: "Guy"),
Person(name: "Magnus", sex: "Girl"),
Person(name: "Sarah", sex: "Girl")
]

@IBOutlet weak var thePeople: UILabel!

func updatePeople()
{
    for peop in personArray{
        thePeople.text = ""
    }
}

【问题讨论】:

  • 你可以使用 stringByAppendingString 或 stringWithFormat 来追加字符串
  • 你到底想做什么?添加文本而不更新?要追加吗?

标签: ios arrays for-loop swift


【解决方案1】:
thePeople.text = thePeople.text+"NewText"

或更短

thePeople.text += "NewText"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多