I am using swift 4 and also I to be trying to create an alertView as soon as I there is an error if signing increase a user making use of Firebase. I have actually an IBAction because that the sign up switch which will sign the user up using text from 2 textfields, one because that email and one for password.

I am usually trying to present an alertview when there is an error through the sign up process, for example there is an empty textfield.

You are watching: Whose view is not in the window hierarchy!


I have attached a screenshot the the duty to wherein that is occuring. I understand that i am in reality getting one error since the print statement outputs an error if there is one.

Regardless the if there is an error or not, over there is no alarm view reflecting up and the application performs the segue regardless.

This is the calculation that i am acquiring for the alertview now showing up.I have looked at all the other posts around this same issue but none seem to work.

ios swift firebase swift4 uialertview
edited january 16 "19 in ~ 8:00

Kaushik Makwana
1,29522 gold badges1212 silver badges2424 bronze title
asked january 16 "19 at 2:53

Steve SahayadarlinSteve Sahayadarlin
1,15833 yellow badges1515 silver badges3131 bronze badges
add a comment |

4 answers 4

energetic oldest Votes
This worry happens because of your watch hierarchy.

You require to discover out what is her Current/Topmost check out controller in see hierarchy and present her alert end it.

To uncover out topmost check out controller use following code:

func getTopMostViewController() -> UIViewController? var topMostViewController = UIApplication.shared.keyWindow?.rootViewController while let presentedViewController = topMostViewController?.presentedViewController topMostViewController = presentedViewController return topMostViewControllerAnd current your alert end topmost see controller and use key thread to existing an alert since closures may have working on one more thread.

DispatchQueue.main.async getTopMostViewController()?.present(alertController, animated: true, completion: nil)Please refer to this ridge answer:Swift 3 attempt to existing whose watch is not in the window hierarchy

edited Mar 19 "20 in ~ 9:14
answered jan 16 "19 at 6:08

Jarvis The AvengerJarvis The Avenger
2,36811 gold badge1616 silver- badges3030 bronze title
| display 1 an ext comment
Try utilizing ViewDidAppear rather of watch did Load.

override func viewDidAppear(_ animated: Bool) super.viewDidAppear(animated) permit alertViewController = UIAlertController(title: "Any", message: "Any tradition Message", preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "ANy", style: .cancel, handler: nil)) present(alertViewController, animated: true, completion: nil)
edited jan 16 "19 in ~ 6:33


Kaushik Makwana
1,29522 yellow badges1212 silver- badges2424 bronze title
answered jan 16 "19 at 3:48

Nishant PathaniaNishant Pathania
34311 silver badge1212 bronze badges
include a comment |
You can get the top many view controller and also have that see controller existing the alert. So rather of self.present usage this approach and see if the works:

let topViewController = UIApplication.shared.keyWindow?.rootViewControllertopViewController?.present(alertController, animated: true, completion: nil)Also try presenting top top the main thread, due to the fact that you"re trying to show the alert in createUser perfect handler:

DispatchQueue.main.async self.present(alertController, animated: true, completion: nil)
edited january 16 "19 in ~ 3:13
answered jan 16 "19 at 3:09
M RezaM Reza
14.7k1313 yellow badges5656 silver- badges6464 bronze title
| present 3 more comments
Check if you have "double tap" issue:

You twin tap button accidentallysignUpBtnPressed is called twiceFirst request is executed correctly, hence launching the segue, and also the error is nilSecond request returns error favor "user already exists", then trying to display alert from existing controller, but segue is currently launched and next controller is already presented

This is addressed by making use of loader through UI prevent (for instance SVProgressHUD) - start loader at the beginning of the an approach and dismiss that in callback.

answered jan 16 "19 in ~ 3:39
4,42244 gold badges3030 silver- badges5050 bronze badges
add a comment |

your Answer

Thanks for contributing an answer to stack Overflow!

Please be certain to answer the question. Carry out details and share her research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based upon opinion; earlier them up with referrals or an individual experience.

To find out more, watch our advice on writing good answers.

See more: 1) Determine Whether The Lines L1 And L2 Are Parallel, Skew, Or Intersecting.

Draft saved
Draft discarded

Sign up or log in

authorize up using Google
authorize up using Facebook
authorize up making use of Email and Password

Post as a guest

email Required, but never shown

Post together a guest


Required, but never shown

article Your answer Discard

By clicking “Post her Answer”, girlfriend agree come our terms of service, privacy policy and cookie policy

Not the price you're spring for? Browse various other questions tagged ios swift firebase swift4 uialertview or questioning your own question.

Google Cloud
Learn an ext about Collectives on ridge Overflow
The Overflow Blog
Featured top top Meta
iOS UISearchController crash: application tried to present modal see controller on itself
Are completion handler closures constantly running in the lift thread?
Swift 3 effort to existing whose watch is no in the home window hierarchy
AlertController view is no in the home window hierarchy
Alert popup existing not functioning in function
Google sign In showing blank screen in iOS
effort to current UIViewController top top UIViewController whose see is no in the window hierarchy
Instantiate and Present a viewController in Swift
present *.viewController top top PFLogInViewController whose view is no in the home window hierarchy
effort to present ~ above firstController whose see is no in the window hierarchy
attempt to current UIAlertController ~ above UITabBarController whose check out is no in the home window hierarchy
Swift 3 effort to existing whose watch is no in the home window hierarchy
effort to present UIAlertController whose check out is not in the home window hierarchy - Swift Error
attempt to existing ... ~ above ... Whose view is no in the window hierarchy
warm Network inquiries an ext hot questions

inquiry feed
subscribe to RSS
question feed To i ordered it to this RSS feed, copy and also paste this URL into your RSS reader.

ridge Overflow
ridge Exchange Network
site style / logo design © 2021 ridge Exchange Inc; user contributions licensed under cc by-sa. Rev2021.9.16.40224

Stack Overflow works ideal with JavaScript enabled

her privacy

By click “Accept every cookies”, friend agree stack Exchange can store cookies on your maker and disclose information in accordance v our Cookie Policy.