arrays - 编译时错误

标签 arrays swift string compiler-errors

let cell = UITableViewCell()
    let dic = dict as Dictionary
    let z = "Period \(String(Int(indexPath.row + 1)))" // something wrong with this
    let x: Array = dic[z] as! Array
    if (x[0] is String) {
        cell.textLabel?.text = x[0] as? String
    } else {
        print("Error: it isnt a string")
    }

    tableView.reloadData()
    return cell

这有什么问题,我觉得这很简单,但我就是看不到它,如果你能看到,请帮助我!谢谢。

当我运行这个程序时,我遇到了段错误,我已将其范围缩小到此代码。再次请帮助。 ;-;

最佳答案

将行更改为:

let z = "Period \(indexPath.row + 1)"

您不需要所有 Actor 。 IndexPath.row 已经是 Int,无需从 Int 创建 String

您还有其他一些严重的问题。假设此代码位于您的 cellForRowAt 方法中,切勿在那里调用 reloadData() 。只需返回一个单元格即可。不要在该方法中对表执行任何其他操作。

您还应该正确地将单元格从表格 View 中出列。它将使您的表格 View 更加高效。

关于arrays - 编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40731817/

相关文章:

java - 泛型数组转换

php - 从 PHP 版本 7.2.0 开始, "Array dereferencing"如何处理 boolean/integer/float/string 类型的标量值?

macos - 如何在 Mac OS X 中创建我自己的 "shell"命令行程序

swift - 将 Firestore 文档的值分配给变量

c 打印字符串语法

c++ - C++中将stdin的内容读入字符串或 vector 的最快方法

java - 如何获取JLabel[ ] [ ]中鼠标点击的标签索引?

c++ - 等价于 C++ 中来自 Java 的枚举的 .values()

ios - Swift 4.2 UITableView Cell 不会自动更改其高度

php - 如何从 PHP 中的字符串中删除电子邮件地址和链接?