0

I do not understand why I still get this:

Thread 1: "Fatal error: Unexpectedly found nil while unwrapping an Optional value."

when I run my app.

The problem comes from a UITableViewCell and it occurs when I want to set the label of the UITableViewCell to a title which comes from an object of type Cella. It is clearly not nil, as clear in the picture, but when setting the label I get this. I made sure I set every class of the correct type, used the correct identifier and everything.

Xcode with Error

class Cella

ViewController1st

ViewController2nd

Sulthan
  • 128,090
  • 22
  • 218
  • 270
Niccolò Diana
  • 119
  • 2
  • 13
  • I know what an optional is. My point is: the variable I’m treating is not nil, and I don’t see any way in which it could be in this context. I do not think it is a duplicate of the post above – Niccolò Diana Mar 08 '19 at 17:38
  • How is `setCell` called, and what is `cellFormatTaken`? It may be `nil`. – Reinhard Männer Mar 08 '19 at 18:43
  • Could `Cella.title` be a force unwrapped optional? – EmilioPelaez Mar 08 '19 at 19:23
  • I've added three more screenshots of my files, I've been trying to look for the error, but no luck so far. Hope they're helpful. – Niccolò Diana Mar 08 '19 at 22:26
  • `title` is `nil`, there is no other possibility. – Sulthan Mar 08 '19 at 23:00
  • Also, please don't post code as images. Post code as text. – Sulthan Mar 08 '19 at 23:01
  • I don't see you registering the cell nib anywhere. – Sulthan Mar 08 '19 at 23:03
  • To be clear, you are probably not registering your cell properly and the nib is not even loaded. That's why your outlets are nil and that's why you get a crash. – Sulthan Mar 08 '19 at 23:15
  • @Sulthan the data I want to display is simply hard coded, I do not think I need any nib as for now. Rather, have printed the value cellFormat.title that I want to assign to cellObject.title.text, and it is a string. But literally on the next line of code, it signals it as "nil". – Niccolò Diana Mar 08 '19 at 23:42
  • @NiccolòDiana Nope, it crashes because the outlet to which you are trying to assign is `nil`. And it is `nil` because there is no nib registered for that table. – Sulthan Mar 08 '19 at 23:48

0 Answers0