【发布时间】:2016-02-21 11:57:31
【问题描述】:
我有一堂课:
class ListOfEventsController: UIViewController, UITableViewDataSource, UITableViewDelegate {
它包含一个函数:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CELL") as! SingleEventCell
当我运行它时 - 它会导致错误提示
fatal error: unexpectedly found nil while unwrapping an Optional value
但是当我去我的故事板时,我看到:
当我点击CELL 时,我会在其属性中看到:
还有:
所以CELL 的标识符已设置,但我仍然收到此错误。
我还能做什么?
【问题讨论】:
-
改变你的 if cell = ...... 到 if let cell = .........
-
尝试 dequeueReusableCellWithIdentifier:forIndexPath 方法
-
@sateesh 我试过了,但是当我运行应用程序时,我看到
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier CELL - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'这很奇怪,因为 - 正如你在我的屏幕截图中看到的 -CELL被用作标识符......跨度> -
在你的视图中注册一个笔尖确实加载方法,这个错误是在说类似的事情
-
我看到您在下面选择了一个答案。正如我在另一个问题中所知道的那样,这是否解决了您的问题,这没有帮助。
标签: ios swift uitableview xcode-storyboard