In my UINavigationController, I add an UIView by code. I want to remove this UIView when my View disappear but I can't find the right way to do that. Here's the I'm using:
var patch: UIView!
override func viewDidLoad() {
super.viewDidLoad()
patch = UIView(frame: CGRectMake(0, 0, view.bounds.width, 20))
patch.backgroundColor = UIColor.redColor()
self.view.addSubview(patch)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(true)
patch.removeFromSuperview()
// or
self.view.willRemoveSubview(patch)
}
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
patch.hidden = true
} else {
patch.hidden = false
}
}
and nothing, view is still there.
I tried even setting patch to nil or to CGRectMake(0, 0, 0, 0) but nothing...
What's the right code to delete it?