ios - 如何将字典的内容转储到 UITextView 或 UILabel 中?

标签 ios swift dictionary uilabel uitextview

我正在尝试将字典的内容显示到 UITextViewUILabel 中。我可以使用 println() 成功完成此操作,但是当尝试将值添加到 .text 属性时,它只会添加第一行。

for (x, y) in dict
{
    println("\(x): \(y)")
    display.text = "("\(x): \(y)") // prints only first item
    display.text = "\(dict)" // prints [item1: 1, item2: 2....] I need it on separate lines and no []. 
}

最佳答案

我不太确定你在问什么。您是否在字符串的多行上要求“(x:y)”?使用换行转义符:

var fullDict = ""

for (x, y) in dict {
    fullDict += "(\(x): \(y))\n"
}

display.text = fullDict

关于ios - 如何将字典的内容转储到 UITextView 或 UILabel 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31685399/

相关文章:

html - 如何调整 webview 内容(包括图像)的大小以水平适应边界

ios - Swift - 搜索 Controller 不断崩溃

ios - 按下 ui 按钮时是否可以更改导航栏颜色?

swift - 有什么方法可以在为 AppStore 存档时检查设置

ios - Xcode - 单元测试 - 为 iOS 12 编译,但模块的最小部署目标为 13

java - 如何向 Spark 数据集添加 Map 列?

google-maps - 谷歌街景标题问题

iOS:将 Cocoapods 从动态库迁移到静态库

python - 与Python dict的组合总和

ios - 调整旋转图像的大小以填充 View