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
Nsstring Containsstring Crashes
Swift - Uiimagepickercontroller - How to Use It
iOS 13 - How to Login in In-App Purchase Sandbox Account
Libmobilegestalt Mobilegestaltsupport.M:153 Mobilegestalt.C:550 Xcode Console
Remembering Scroll Position on Uitableview
How to Check If Device Can Make a Phone Call (iOS 8)
Issue with Auto Layout on iOS 8 (Code Works Perfectly on iOS 7)
Swift - Coredata Migration - Set New Attribute Value According to Old Attribute Value
iOS Glsl. How to Create an Image Histogram Using a Glsl Shader
Number of Days in the Current Month Using iOS
Crashlytics iOS - Log Caught Exception
Setting Maximum Number of Characters of 'Uitextview ' and 'Uitextfield '
How to Cache Videos? iOS - Swift
How to Set an Title of the Currently Playing Audio in iPhone Lock Screen
Avcapturevideopreviewlayer Orientation - Need Landscape