I am using swift 4
and I am trying to create an alertView
when I there is an error while signing up a user using Firebase
. I have an IBAction
for the sign up button which will sign the user up using text from two textfields
, one for email and one for password.
I am basically trying to show an alertview
when there is an error with the sign up process, for example there is an empty textfield
.
I have attached a screenshot of the function to where that is occuring. I know that I am in fact getting an error because the print statement outputs an error if there is one.
Regardless of if there is an error or not, there is no alert view showing up and the app performs the segue regardless.
2019-01-15 21:40:26.368924-0500 Pronto[9036:225268] Warning: Attempt to present on whose view is not in the window hierarchy
This is the output that I am getting for the alertview now showing up. I have looked at all the other posts about this same issue but none seem to work.
Try using
ViewDidAppear
instead of View did Load.Check if you have "double tap" issue:
signUpBtnPressed
is called twiceThis is fixed by using loader with UI blocking (for example SVProgressHUD) - start loader at the beginning of the method and dismiss it in callback.
This issue happens due to your view hierarchy.
To find out topmost view controller use following code:
And present your alert over topmost view controller and use main thread to present an alert because closures always work on another thread.
Please refer to this stack answer: Swift 3 Attempt to present whose view is not in the window hierarchy
You can get the top most view controller and have that view controller present the alert. So instead of
self.present
use this approach and see if it works:Also try presenting on the main thread, since you're trying to show the alert in createUser completion handler: