0

I'm trying to do something quite simple, actually I have just started a new project and I have added a button in the main view of the Storyboard. Then when I click on this button, it just load a new view which is in my xib file. For that, I use this line code :

if let newView = NSBundle.mainBundle().loadNibNamed("myView", owner: self, options: nil).first as? myView {
            contentView.addSubview(newView)
        }

So until here, everything works. But now, I want to add in my class (UIView) which is linked to my xib file, a IBOutlet. For that, I just do "CTRL + Drag" my view in my class and add a IBOutlet, but from there, I have an error when I run the program : setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key...

I have search for an answer, but on Internet everyone just say to remove the IBOutlet. So of course after that it works, but I need to have it. Is there a way to do that ? Actually I think yes because I have downloaded a project on github and it works. Actually, I just try to reproduce what he has done, but I always have my error. The git project I try to do is this one : https://github.com/J3Patel/collectionView-iOS-Swift

Thanks for your help :)

Rgds,

Adz
  • 281
  • 3
  • 16
  • Would it be possible to move the view out of the xib, and into the storyboard? You can use an IBOutlet in the storyboard to reference the view, or use an embedded view controller if it needs to do something complicated. – Luke Van In Jul 07 '16 at 23:56
  • Yes indeed, I can create my view in the storyboard and not in the xib. Actually, I have always used the storyboard, it's my first time with xib but I thought it was a "best practice". But if it is easier in Storyboard, I'll do this! Thank you ! – Adz Jul 08 '16 at 06:33

0 Answers0