I've pulled up an old project trying to reuse some functionality.
I've created a nib with a UIView subclass. In the original, working version I didn't need to set File's owner
in IB. However, I'm receiving errors alluding that I now need to do so (Xcode 7): loaded the "TipView" nib but the view outlet was not set.
So I proceeded to hook the File's owner
up to the view controller that is responsible for setting up the view. Here's the relevant code from the View Controller:
class TipViewController: UIViewController {
private let kTipViewHeight: CGFloat = 400
private let kTipViewWidth: CGFloat = 300
override func viewDidLoad() {
super.viewDidLoad()
if let tipView = createTipView() {
let center = CGPoint(x: CGRectGetWidth(view.bounds)/2, y: CGRectGetHeight(view.bounds)/2)
tipView.center = center
view.addSubview(tipView)
}
}
func createTipView() -> UIView? {
if let view = UINib(nibName: "TipView", bundle: nil).instantiateWithOwner(nil, options: nil).first as? TipView {
view.frame = CGRect(x: 0, y: 0, width: kTipViewWidth, height: kTipViewHeight)
return view
}
return nil
}
}
extension UIViewController {
func presentTips(tips: [Tip], animated: Bool, completion: (() -> Void)?) {
let controller = TipViewController()
controller.modalTransitionStyle = .CrossDissolve
presentViewController(controller, animated: animated, completion: completion)
}
}
I tried setting instantiateWithOwner
to: .instantiateWithOwner(self, options: nil).first
(changed nil
to self
) also to no avail.
This is the relevant presenting view controller code:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
presentTips([], animated: true, completion: nil)
}
The UIView subclass doesn't do anything out of the ordinary, so I haven't bothered to include its code.
When I make the changes requested - add TipViewController as the nib's File owner and hook up its view
outlet to the nib view - I get a range of error messages depending on which configurations I take ranging from:
this class is not key value coding-compliant for the key view.
Can't add self as subview
Not sure why I was able to use a nib without a file's owner in Xcode 6, but am not able to do so as of Xcode 7 - haven't found any material or release notes related to the change, so I'm a little stumped for now.
Any help is very much appreciated.