gpt4 book ai didi

ios - 在通过代码呈现的另一个 ViewController 上呈现 AlertController

转载 作者:行者123 更新时间:2023-11-29 01:44:35 24 4
gpt4 key购买 nike

我通过空 VC 上的代码实例化了 Parse 的常用 UI 登录屏幕。如果未验证用户的电子邮件,我想显示一个 AlertController。因此,我将通过代码创建的 logInViewController 来呈现 AlertController...我理解 AlertController 不在窗口层次结构中的错误,但我不确定如何解决它。如果我关闭 logInViewController 但我不想这样做,它会起作用,我希望它存在于后台。使用 swift 。

这个答案没有找到确切的问题:AlertController is not in the window hierarchy

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)
}

}

最佳答案

在您的 logInViewController(logInController:didLogInUser:) 函数中,更改行

self.presentViewController(alertController, animated: true, completion: nil)

logInController.presentViewController(alertController, animated: true, completion: nil)

这将在登录 Controller 的顶部显示警报 Controller ,而不是空的 View Controller 。

关于ios - 在通过代码呈现的另一个 ViewController 上呈现 AlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32073994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com