Frank Boccia Frank Boccia - 1 year ago 63
iOS Question

Removing a UIView and bringing back the UIView in swift

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 {

Answer Source
@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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download