Present AlertController Over another ViewController presented via code
我通过空VC上的代码实例化Parse的库存UI登录屏幕。如果用户的电子邮件未验证,我想显示一个AlertController。因此,我通过代码创建的logInViewController呈现了alertController...。我理解AlertController不在窗口层次结构中的错误,但是我不确定如何解决。如果我关闭logInViewController但我不想这样做,则希望它在后台存在,它可以工作。使用Swift。
此答案未解决确切的问题:AlertController不在窗口层次结构中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if (PFUser.currentUser() == nil) { //build logInVC in Code: var logInViewController = PFLogInViewController() var logInLogoTitle = UILabel() logInLogoTitle.text ="Thredz" logInLogoTitle.font = UIFont(name:"Cochin", size: 40.0) logInViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.PasswordForgotten | PFLogInFields.Twitter logInViewController.logInView?.backgroundColor = UIColor.whiteColor() logInViewController.logInView?.logo = logInLogoTitle logInViewController.delegate = self //present log in VC self.presentViewController(logInViewController, animated: true, completion: nil) //build signUpViewController var signUpViewController = PFSignUpViewController() signUpViewController.delegate = self var signUpLogoTitle = UILabel() signUpLogoTitle.text ="Thredz" signUpViewController.signUpView?.logo = signUpLogoTitle logInViewController.signUpController = signUpViewController } } func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) { if (PFTwitterUtils.isLinkedWithUser(user)) { var twitterUsername = PFTwitterUtils.twitter()?.screenName PFUser.currentUser()?.username = twitterUsername PFUser.currentUser()?.saveEventually(nil) } if user["emailVerified"] as! Bool == true { dispatch_async(dispatch_get_main_queue()) { self.performSegueWithIdentifier(self.peopleTableViewControllerSegue, sender: nil) } } else { // User needs to verify email address before continuing let alertController = UIAlertController( title:"Email address verification", message:"We have sent you an email that contains a link - you must click this link before you can continue.", preferredStyle: UIAlertControllerStyle.Alert ) alertController.addAction(UIAlertAction(title:"OK", style: UIAlertActionStyle.Default, handler: nil) ) self.presentViewController(alertController, animated: true, completion: nil) } } |
在您的
1 | self.presentViewController(alertController, animated: true, completion: nil) |
到
1 | logInController.presentViewController(alertController, animated: true, completion: nil) |
这会将警报控制器显示在登录控制器的顶部,而不是空白视图控制器。