1

I have an XCode project with a main storyboard and main ViewController. There are then 4 sub classes/xib files which can be swiped as pages. This is all working fine, but as soon as I add a label and link it up as an IBOutlet the app does not build successfully and I get this error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7ff7cc0953b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key daysCountDaysLabel.'

I've been stuck on this for hours and followed solutions from 10 or so similar (and resolved!) posts on Stack Overflow without it working for me.

Things I have tried:

  • Making sure there are no IBOutlets that don't match labels
  • Removing all the labels/IBOutlets, testing it works and then adding a new label and matching up to an IBOutlet (which then doesnt work)
  • Cleaning the build
  • Checking the source for the .xib files to see if there any old outlets etc
  • Making sure class names match up
  • Stopping myself posting on Stack Overflow with something that seems easy to fix as there are so many other resolved posts with the same issue (sorry)

I have zipped up the project and placed here in case anyone can identify and solve the issue: http://expirebox.com/download/87ccb8b70612ef3c86a447ff5eb8d728.html

Friendly Code
  • 1,585
  • 1
  • 25
  • 41

4 Answers4

3

Well I went through the attached file and I think this might be the problem:

let vc0 = UIViewController(nibName: "ViewControllerDays", bundle: nil)

You are instantiating a UIViewController when it should have been ViewControllerDays

So that is why it fails at runtime as its trying to access it as a UIViewController which does not have any of these properties.

And this happens in a lot of places. You need to init with the proper view controller class.

GoodSp33d
  • 6,252
  • 4
  • 35
  • 67
  • Thanks for looking in to it. Although I tried your suggestions and got a new error. What makes me think this part is OK is if you remove the label and IBOutlet the project builds and runs fine – Friendly Code Jul 29 '16 at 12:07
  • 1
    As @GoodSp33d said. This one of the errors, after that there is a new swift error but for your question this is the solution. I would advice to create a new question with the new error. – Otávio Jul 29 '16 at 12:54
  • 1
    @FriendlyCode, this shud solve your problem. What error did you get? I tried the same way and it worked for me. – Teja Nandamuri Jul 29 '16 at 12:56
  • @FriendlyCode think you must have removed the View outlet too. YOu should connect the view outlet to your xib, and everything shud be fine. – Teja Nandamuri Jul 29 '16 at 12:57
2

sorry I can not able to download your sorce code due firewall restriction. :(

1) check all your xib and storyboard you must have "daysCountDaysLabel" label connected and not declared in .h or .m file removed it.
2) window -> projects -> project name delete direved data and try again
Bhushan Vaidya
  • 722
  • 1
  • 6
  • 17
  • Honestly it's not declared anywhere. I know this because if I remove all labels and IBOutlet connections it works. Then when I add a test one it breaks again. I'm working with Swift so no .h or .m - tried the delete derived data but sadly it didn't fix it – Friendly Code Jul 29 '16 at 12:13
1

So, I see two issues in your project, first of all your xib file contain UIViews instead of UIViewController.Also, they are not linked to your custom ViewController Class. For example, ViewControllerDays.xib contains a UIView in which you are adding labels. So, firstly you need to delete that UIView and add UIViewController instead. Then you link that ViewController to ViewControllerDays. This was one of the major problem.

Secondly, there is no file's owner to your label, you need to provide that as ViewControllerDays(or the ViewController in which it is added ). Hope you understood my point.

this class is not key value coding-compliant for the key error is answered in this link.

Community
  • 1
  • 1
Sanchit Kumar Singh
  • 513
  • 1
  • 5
  • 17
0

problem is

daysCountDaysLabel

find it in project and check outlets/setting text to it

Lu_
  • 2,577
  • 16
  • 24