在展开 Optional 值时迅速且意外地发现 nil [英] swift and unexpectedly found nil while unwrapping an Optional value

查看:32
本文介绍了在展开 Optional 值时迅速且意外地发现 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堂课:

class ListOfEventsController: UIViewController, UITableViewDataSource, UITableViewDelegate {

并且它包含一个函数:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("CELL") as! SingleEventCell

当我运行它时 - 它会导致一个错误,提示

and when I run it - it causes an error that says

fatal error: unexpectedly found nil while unwrapping an Optional value

但是当我转到我的故事板时,我看到:

but when I go to my story board I see:

当我点击 CELL 时,我会在它的属性中看到:

and when I click CELL I see in its properties:

还有:

所以 CELL 的标识符已设置,但我仍然收到此错误.

so the identifiers for CELL are set up, but I'm still getting this error.

我还能做什么?

推荐答案

  1. 在 Storyboard 中选择您的原型单元
  2. alt + cmd + 4 打开属性检查器
  3. CELL 写入 Identifier 字段.
  1. In Storyboard select your prototype cell
  2. alt + cmd + 4 to open the Attribute Inspector
  3. Write CELL into the Identifier field.

然后再试一次;)

这篇关于在展开 Optional 值时迅速且意外地发现 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆