【发布时间】:2016-10-15 05:23:49
【问题描述】:
我在 swift 3.0 中使用带有自定义单元格的 tableview。我使用了一个 textview 并给出了 tabelview 单元格类的出口并在 tableview 委托方法中访问,但它向我显示了错误,例如 unexpectedly found nil while unwrapping an Optional value
这是我的代码。 记录是数组
查看此屏幕截图。仅供参考,我参加了一个新的自定义课程并为其提供了插座,但出现了同样的问题
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return record.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCell")
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
if let str = record.object(at: indexPath.row) as? String {
print(cell.txtview)
cell.txtview.text = str
}
return cell
}
它在静态单元格中完美运行,但在自定义单元格中显示错误。
cell.textview 不是来自自定义单元格
请帮帮我
【问题讨论】:
-
自定义单元格的标识符是什么,请检查是否有问题
-
根据我的代码,我给了它相同的类和相同的标识符。但是标识符是作为字符串给出的,所以这不是问题
-
No @JAL 它在 siwft 3.0 中,如果它在 swift 2.0 或更低版本中,那么我已经解决了
-
读取链接的副本。它与 Swift 语言版本无关。
-
@JAL 你不能给出重复的问题,因为它在 swift 2.0 和 swift 3.0 中有很多变化,你不,这个问题不是自定义单元格,它的 tableview 默认单元格。
标签: ios uitableview swift3