【问题标题】:cannot subscript of type [String]不能为 [String] 类型的下标
【发布时间】:2016-01-28 05:32:12
【问题描述】:

我收到此错误:

        cell.naamItem = VragenInformatie[indexPath.section][indexPath.row][0]

我在同一个班级有这个:

    var VragenInformatie: [[[String]]] = [[[]]]

这就是数组的样子:

var VragenInformatie: [[[String]]] = [[["Spelletjeskamer",""],["Keuken",""],["Garage",""],["Binnenplaats",""],["Zitkamer",""],["Slaapkamer",""],["Studeerkamer",""],["Eetkamer",""],["Badkamer",""]],[["De Wit",""],["Pimpel",""],["Blaauw van Draet",""],["Roodhart",""],["Groenewoud",""],["Van Geelen",""]],[["Loden pijp",""],["Pistool",""],["Engelse sleutel",""],["Dolk",""],["Touw",""],["Kandelaar",""]]]

我真的不知道问题出在哪里,我也不知道下标的真正含义

有人能给点建议吗?

【问题讨论】:

  • 错误信息是什么?右侧表达式的结果是StringnaamItem 也是 String 吗?
  • cell.naamItem 是字符串吗?
  • [[[]]] 很多。 LISP 怀旧?

标签: arrays swift subscript


【解决方案1】:

我敢打赌你的naamItem 是一个UILabel 或类似的东西,而你忘了附加'.text'。如果我的理论是正确的,你的代码应该是这样的:

cell.naamItem.text = VragenInformatie[indexPath.section][indexPath.row][0]

naamItem 不是 UILabel、UITextView 或 UITextField 的任何其他情况下,您应确保 naamItem 的类型为 String

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多