eggswift / pull-to-refresh

#Busy Re-Building....# An easy way to use pull to refresh and infinite scrolling in Swift. Pod 'ESPullToRefresh'
MIT License
1.82k stars 252 forks source link

fatal error: attempted to read an unowned reference but the object was already deallocated #98

Open siberianisaev opened 6 years ago

siberianisaev commented 6 years ago

Xcode 9 / Swift 4

on self.addObserver(newSuperview) of ESRefreshComponent

open override func willMove(toSuperview newSuperview: UIView?) {
        super.willMove(toSuperview: newSuperview)
        /// Remove observer from superview immediately
        self.removeObserver()
        DispatchQueue.main.async { [unowned self, newSuperview] in
            /// Add observer to new superview in next runloop
            self.addObserver(newSuperview)
        }
    }