UITableViewAlertForLayoutOutsideViewHierarchy error: Warning once only (iOS 13 GM)

前端 未结 10 604
说谎
说谎 2020-12-25 12:23

I am getting a strange error with iOS13 when performing a Segue and I can\'t figure out what it means, nor can I find any documentation for this error. The problem is that t

10条回答
  •  囚心锁ツ
    2020-12-25 12:58

    extension UIView {
    
      func rootView() -> UIView {
         var view = self
         while view.superview.isNotNil {
             view = view.superview!
         }
         return view
      }
    
      var isOnWindow: Bool {
         return self.rootView() is UIWindow
        }
      }
    

    then you just need to check if your tableView isOnWindow like...

    if self.tableView.isOnWindow {
    /// do stuff
    }
    

    Disclaimer: as the documentation explains, you may need to defer the call which means that there is no warranty your method will be called again so it's your responsibility to perform your update when isOnWindow is true.

提交回复
热议问题