Error: Uiview's Window Is Not Equal to Another View's Window

Error: UIView's window is not equal to another view's window

You seem to have some fundamental misunderstandings of iOS programming paradigms. You have segues attached to your buttons, but you also then call performSegue in code. When you have a segue attached to a control, you don't need any code (and shouldn't have any) to cause the segue to execute. You also shouldn't go back to a previous view controller with a segue, other than an unwind segue; you're not really going back, you're creating a new instance of the controller you think you're going back to. This will cause a build up of controllers (as none will be deallocated) until your app runs out of memory.

So, you should delete the function, letsPlayButton: from MainScreen, and also get rid of it in the storyboard (the segue attached to that button is all you need).

Delete the segue you have going "back" from GameScreen to MainScreen, and change the code in backToMainScreen to this,

@IBAction func backToMainScreen(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}

UIAlertController keeps segue from performing (window is not equal to view’s window“)

You can't present an alert and do a segue at the same time use DispatchQueue.main.asyncAfter to mook a waiting

private func setUpDialog() {
alertMessage = "Logging in"
alert = UIAlertController(title: "Please wait", message: alertMessage, preferredStyle: UIAlertController.Style.alert)
self.present(alert, animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.alert.dismiss(animated: true, completion: {
self.performSegue(withIdentifier: "segue12", sender: self)
})
}
}

Can't interact with UIView added to Window

I ended up resolving the issue by completely swapping out the root view controller rather than simply adding it's view as a subview. The problem was as @DonMag pointed out that I was adding the subview without it's view controller. I found this question about swapping the root view controller and used that as a basis for my changes. If someone wants to provide a complete solution that doesn't require swapping the root view controller I'll accept that instead.



Related Topics



Leave a reply



Submit