I am using a UIView not a view controller/ I am removing the view once the delete button is clicked. I am trying to make the view come back when a user wants the view back. example : myView.removeFromSuperview() Is there anyway to bring the view back? In swift thank you guys!
@IBOutlet weak var brokeView: UIView!
@IBOutlet weak var deleteButton: UIButton!
@IBAction func deleteViewButton(sender: AnyObject) {
if brokeView != nil {
brokeView.removeFromSuperview()
}
Adds a view to the end of the receiver's list of subviews.
@IBOutlet weak var brokeView: UIView!
you already have a reference to the view brokeView
which you are going to remove and add again, but its weak
so it will be deallocated once it is removed from superView
. Since you need this brokeView
to add back make it strong
.
@IBOutlet var brokeView: UIView!
Now you can add it back like
view.addSubview(brokeView)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With