我想在我的 UITableViewCells 中使用字典中的值。我可以通过使用 indexPath.row 作为值并使用 indexPath.section 作为键从字典中获取它们吗?
最佳答案
你可以获取键数组并在 indexPath.section
中获取键,如下所示:
Array(yourDictionary.keys)[indexPath.section]
您可以像这样从值数组中获取 indexPath.row
中的值:
Array(yourDictionary.values)[indexPath.row]
编辑:
如果你想获取特定部分键的值,你应该这样写:
let key = Array(yourDictionary.keys)[indexPath.section]
let array = yourDictionary[key]
let value = array[indexPath.row]
关于Swift:通过索引访问字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31775724/