Search code examples
iosswiftuitableviewxcode-storyboard

swift and unexpectedly found nil while unwrapping an Optional value


I have a class:

class ListOfEventsController: UIViewController, UITableViewDataSource, UITableViewDelegate {

and it contains a function:

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

enter image description here

but when I go to my story board I see:

enter image description here

and when I click CELL I see in its properties:

enter image description here

and also:

enter image description here

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

What else can I do?


Solution

    1. In Storyboard select your prototype cell
    2. alt + cmd + 4 to open the Attribute Inspector
    3. Write CELL into the Identifier field.

    Then try again ;)

    enter image description here