Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: I got " Unexpectedly found nil " in "tableView.delegate=self"

I connect a segue between a button and a view controller as shown in the screenshoot. I connect a segue between a button and a view controller.

Everything works until I choose the class as "ViewController". enter image description here

Every time I click the "Add" button, the code crashes with following error:"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" enter image description here

I'm really confused now. Can anyone help me this?

like image 233
Mada_DE_Siyuan Avatar asked Dec 19 '25 12:12

Mada_DE_Siyuan


1 Answers

You are getting crash bcoz table view is not connected as IBOutlet.

You need to connect table view IBOutlet in to view controller. You can do it by assistant editor top right corner (a double circle button intersecting each other) and drag and drop by pressing right click from table view to the view controller.

Once IBOutet is connected, in view controller there will be a dark gray color circle in before a property indicates that it will be connected successfully.

enter image description here

If circle is not filled then it means that property is not connected as IBOutlet.

enter image description here

See pic.

enter image description here

like image 198
Mahendra Avatar answered Dec 22 '25 09:12

Mahendra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!