0

I have a custom UIViewController with a Table View inside.

I control-dragged the Table View from the Scene in Main.storyboard to the class to get an outlet for the Table View, naming it "tableView".

It then added this line to my class:

@IBOutlet weak var tableView: UITableView!

I wanted to change the name to tvMC so I deleted the line and control-dragged the Table View again, this time naming it "tvMC".

I built and ran and got this error:

Terminating app due to uncaught exception 'NSUnknownKeyException' ...
this class is not key value coding-compliant for the key tableView.'

I decided to just use tableView to make it work, but after changing the outlet back to tableView, I got this error:

Terminating app due to uncaught exception 'NSUnknownKeyException' ...
this class is not key value coding-compliant for the key tvMC.'

It seems like because I control-dragged it twice, that even though I deleted one of them the key still exists somewhere.

So how can I see the list of keys I have created for UI elements and delete the ones I don't need?

Gimme the 411
  • 994
  • 9
  • 25

2 Answers2

2

You are creating two instances of same UI element in UIStoryboard

Select your UIViewController in storyboard

enter image description here

Now select connections Inspector in the utility section on the right side

enter image description here

In outlet sections, you can find two connections for tableView delete one and your app now runs well.

Always make sure to delete connections in storyboard first then in code.

iamVishal16
  • 1,780
  • 18
  • 40
1

Whenever you want to change the name of an outlet , you have to delete the old one , since typing other names doesn't update the hooked name inside IB resulting in a crash when you run

enter image description here

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87