UITableViewAlertForLayoutOutsideViewHierarchy error: Warning once only (iOS 13 GM)

前端 未结 10 606
说谎
说谎 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:57

    In viewDidDisappear method I declare tableView.setContentOffset(CGPoint(x: 0, y: 0), animated: false) function. Some of you says it's not important but it affected tableView delegate methods. For example viewForHeader function is not called when I get this warning.

    0 讨论(0)
  • 2020-12-25 12:58

    It happened to me because I registered the device for change orientation notification in the viewWillAppear(:) method. I moved the registration in the viewDidAppear(:) and Xcode it's not stopping at the breakpoint anymore.

    What I can say is that layout changes might be run when the view is already visible...

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-25 12:59

    I'm new to Xcode/Swift so this may or may not help anyone. I started getting this error after updating to iOS 13 and Xcode 11 within the app when going back to a list from a detail view.

    I found that I was doing a tableView.reloadRows and tableView.insertRows in the unwind(as suggested by Apple in one of their tutorials)

    @IBAction func unwindToMealList(sender: UIStoryboardSegue) {
        if let sourceViewController = sender.source as? MealViewController, let meal = sourceViewController.meal {
    
            if let selectedIndexPath = tableView.indexPathForSelectedRow {
                // Update an existing meal.
                meals[selectedIndexPath.row] = meal
                tableView.reloadRows(at: [selectedIndexPath], with: .none)
            }
            else {
                // Add a new meal.
                let newIndexPath = IndexPath(row: meals.count, section: 0)
    
                meals.append(meal)
                tableView.insertRows(at: [newIndexPath], with: .automatic)
            }
        }
    }
    
    )
    

    I commented out that section of code and it went away.

    Oddly enough leaving the sort and self.tableView.reloadData() didn't give me the error.

    0 讨论(0)
提交回复
热议问题