简体   繁体   中英

Swift remove reference to UIView

I want to completely remove a reference to a UIView when it is tapped (it is a subview.

@IBAction private func handleTap(_ sender: UITapGestureRecognizer) {
    if (delegate != nil) {
        delegate?.imageWasTapped(imageView.image!, photoURL: photoURL!)
        self.removeFromSuperview()
    }
    print ("tap")
}

removeFromSuperview() seems to be insufficient to completely remove the instance (from what I've read), so would like to

self = nil

but of course self is immutable.

I tried to pass the value to my superview as an inout argument, but of course self is still immutable.

        delegate?.imageWasTapped(imageView.image!, photoURL: photoURL!, imageView: self)

Is removeFromSumerview() sufficent to deallocate a UIView from memory, or how is this best done?

You can weak reference to that UIView . Then the UIView will be nil with ARC after you removed it by using removeFromSuperview .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM