【问题标题】:Cannot call value of non-function type '[String]'无法调用非函数类型“[String]”的值
【发布时间】:2019-03-10 16:09:14
【问题描述】:

我想将原型单元格中的标签文本设置为存储在数组中的字符串。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "unitOptionCell", for: indexPath)

    cell.textLabel?.text = currentConvertion.availableUnits(indexPath)

    return cell
}

数组如下:

var availableUnits: [String] {
    switch category {
    case .firstCategory:
        return ["test 1", "test 2", "test 3"]
    case .secondCategory:
        return ["test 4", "test 5", "test 6"]
    case .thirdCategory:
        return ["test 7", "test 8", "test 9"]
    }
}

哪里出错了?

【问题讨论】:

    标签: arrays swift string uitableview cell


    【解决方案1】:

    如果您使用括号,编译器会解释您正在尝试调用一个函数。您应该使用方括号访问数组的元素,例如:

    cell.textLabel?.text = currentConvertion.availableUnits[indexPath.row]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-02
      • 2017-08-16
      • 2020-02-01
      • 2021-01-15
      • 2021-03-30
      • 2016-03-10
      • 2016-09-26
      • 2017-06-27
      相关资源
      最近更新 更多