-2

I'm getting a crash when connecting a UIKit element to my storyboard.

Error code:

Exception   NSException *   "[<UIViewController 0x7f818646dd30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key labelProva."   0x0000600002ed0c60

Here is the code of the View:

import UIKit

class WelcomeViewController: UIViewController {



@IBOutlet weak var labelProva: UILabel!



override func viewDidLoad() {
    super.viewDidLoad()
    
    title = K.nomeApp
    
    labelProva.text = "Buongiorno e benvenuto su MPB"
    labelProva.text = K.App_Text.tutorialApp
    }
}

App structure

Label Connection Inspector

Various screeshot on the view's info:

Class and other info

Values

Segues and connections

  • 2
    Have you set the offending view controller to be of your desired class? – valeCocoa Nov 22 '21 at 10:11
  • send the screenshot by select Your Label in your storyboard and Click on show the connections inspectors – Gowtham Nov 22 '21 at 10:12
  • @valeCocoa If you mean trying to set it as 'UITableViewController' instead of 'UIViewController', yes I did and unfortunately it did not work. – Michelangelo Amoruso Manzari Nov 22 '21 at 10:22
  • @Gowtham I added a screenshot as requested. – Michelangelo Amoruso Manzari Nov 22 '21 at 10:23
  • 1
    No you should set the offending view controller in the storyboard to be of the same type of your subclaass `WelcomeViewController`. – valeCocoa Nov 22 '21 at 10:24
  • @valeCocoa so you mean to set the WelcomeViewController as UITabViewController? WelcomeViewController is a subview of a TabBarController as you can see from the screenshot. The offending view is WelcomeViewController. – Michelangelo Amoruso Manzari Nov 22 '21 at 10:26
  • You declared `labelProva` but not used anywhere. You used `welcomeLabel` & `welcomeTutorialLabel` but not declared anywhere. How it run even? – Fahim Parkar Nov 22 '21 at 11:18
  • I'm sorry, the code was actually wrong here, but correct on my side, it was old code. I edited the questiion for you to see. – Michelangelo Amoruso Manzari Nov 22 '21 at 13:17
  • The last view controller on the right, that has to be set of type `WelcomeViewController` In your storyboard. That is done via its info panel in Interface Builder. You might as well also need to reconnect the label in Interface Builder to the IBOutlet in your code. – valeCocoa Nov 23 '21 at 11:34
  • @valeCocoa the view controller on the right was already setted in that way. I tried reconnecting the label multiple times and it did not work. Any more ideas on why this is giving problems? Also, I'm adding a feew more screenshots for reference. – Michelangelo Amoruso Manzari Nov 23 '21 at 16:31
  • Try to clean, since the settings in Storyboard are correctly set. Check/uncheck `Inherits Module from Target` (sometimes it triggers it)... – Larme Nov 23 '21 at 16:39
  • @Larme thanks for the comment, after a few hours of fiddling with it I tried disassembling and riassembling the view and app and it randomly started working. Couldn't find out what was causing the bug, I'll add an answer to my question for future reference. – Michelangelo Amoruso Manzari Nov 23 '21 at 16:53

1 Answers1

-2

I solved this problem by deleting the culprit part of my app and rebuilding it from scratch. I couldn't find the bug that was causing all of this, but this approach solved the problem somehow.

I'll mark my answer as the correct one so that anyone who has this problem can try and solve it like this.

Procedure:

  1. Delete all connections to the affected view(s);
  2. Delete the view(s);
  3. Redo all the view(s) and connections.

Hope this helps anyone having the same issues!