Followup on this question.
I have an app, where the main view has one button, and a file 'popup.xib' which is now empty (Just a view, no buttons, no labels, nothing). And I want it to popup when I press the button. For some reason I get the following error whenever I press the button:
... this class is not key value coding-compliant for the key view.'
I have read that this is because of outlets from the NIB which have been deleted or changed, that's why I removed all objects and what to display an empty view. But I still get this error.
My code:
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBAction func showPopup(sender: AnyObject) {
var x = UINib(nibName: "Popup", bundle: nil);
println(x)
var y = x.instantiateWithOwner(nil, options: nil)
println(y)
var z = y[0] as? PopupViewController
println(z)
z!.show(self.view)
}
}
PopupViewController.swift
import UIKit
class PopupViewController : UIViewController {
func show(tView : UIView) {
tView.addSubview(self.view)
self.view.backgroundColor = UIColor.redColor()
}
}
The output:
<UINib: 0x7ff822412f90>
2015-02-02 15:47:57.870 tttt[5437:179808] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7ff822553ec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
Update
Update 2
I continued tweaking stuff according to the answers and comments, and got if I do var y = x.instantiateWithOwner(PopupViewController(), options: nil)
the line get executed OK. But then I get back an array containing a UIView, not a UIViewController. Therefore the last line z!.show(self.view)
causes a crash. I know it creates the right nib, cause the properties (e.g. alpha value) that I changed appear in the text output from println(y)
correctly.
So my question now is: What should I pass as the owner into instantiateWithOwner
?