无法将类型[[(String)]'的值分配给类型'String!'的值? [英] Cannot assign a value of type '[(String)]' to a value of type 'String!'?
问题描述
woodText.text = [String](textForWood.values)
这是我的代码. woodText
是UITextView
,而textForWood
是字典.请帮忙.
woodText.text = [String](textForWood.values)
This is my code. woodText
is a UITextView
, and textForWood
is a dictionary. Please help.
推荐答案
woodText.text = textForWood["Oak"] as! String
您需要将字符串分配给UITextView
的text
.上面显示了如何从字典中提取字符串.
You need to assign a String to the text
of a UITextView
. The above shows how to extract a String from a Dictionary.
基于评论的添加
我认为使用字典来填充表格视图不是一个好主意. (请记住,字典没有顺序,数组是有序的.)您应该拥有某种类型的数组,该数组可以通知表视图它应该显示多少行以及在那些行中显示什么.
I don't think using a dictionary to populate a table view is a good idea. (Remember, dictionaries are not ordered, arrays are.) You should have an array of some kind that informs the table view how many rows it should display and what to display in those rows.
一种解决方案是字典数组([[String : String]]
).然后,您可以填充cellForRowAtIndexPath
中的每个单元格.每行的字典应包含
One solution would be an array of dictionaries ([[String : String]]
). You can then populate each cell in cellForRowAtIndexPath
. The dictionary for each row should contain something like
["name" : "Oak", "text" : "The text to display in the oak cell..."]
使用标准样板代码用文本视图使单元出队,然后
Use the standard boilerplate code to dequeue the cell with the text view and then
let woodDictionary = textForWood[indexPath.row]!
woodText.text = woodDictionary["text"] as! String
这篇关于无法将类型[[(String)]'的值分配给类型'String!'的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!