【问题标题】:IOS Alert not up / Click Alert to go to next page SWIFTIOS 警报未启动/单击警报转到下一页 SWIFT
【发布时间】:2015-05-06 15:08:32
【问题描述】:

我有下面的代码,一旦用户注册他们的帐户,它就会将我带到登录页面。我想不通的是如何在创建帐户时弹出警报框,并且用户停留在注册页面上,直到他们单击警报框底部的“登录”按钮,然后将他们重定向到登录页。关于如何在下面更改我当前的代码有什么想法吗?

    // Display alert message with confirmation
    var alert = UIAlertController(title: "Registration Successful", message: "You may now login. Thank You!", preferredStyle: UIAlertControllerStyle.Alert)

    let okAction = UIAlertAction(title:"Login", style: UIAlertActionStyle.Default){ action in
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    alert.addAction(okAction)


}

func displayAlertMessage(userMessage:String) {
    var alert = UIAlertController(title:"Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert)

    let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.Default, handler: nil)

    alert.addAction(okAction)

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

}

【问题讨论】:

  • 如何注册用户?我猜您的服务器会在创建用户后发回“成功”消息。
  • 目前它只是将数据保存在本地,因为我还没有将它发送到数据库。只是想先完成格式化。

标签: ios swift ios8


【解决方案1】:

因此,我假设您希望在标题中显示“注册成功”的警报,并显示“您现在可以登录。谢谢!”的消息它只有一个登录按钮(没有取消按钮)。

我认为,您的代码中缺少的是该登录操作的处理程序。 试试这个:

func displayLoginAlert() {

    var alert = UIAlertController(title:"Registration successful", 
                                  message:"You may now login. Thank You!", 
                                  preferredStyle: UIAlertControllerStyle.Alert)

    let loginAction = UIAlertAction(title:"Login", 
                                    style:UIAlertActionStyle.Default) { (UIAlertAction) -> Void in
        // HERE you perform the segue to your LoginVC, 
        // or do whatever else you wanna do when the user clicked "Login" :)
        // for example: 
        self.performSegueWithIdentifier(theIDOfYourSegueToTheLoginVC, sender:self)
    } 

    alert.addAction(loginAction)

    self.presentViewController(alert, animated: true, completion: nil)
}

注意,只有当您的部署目标是 iOS 8.0.0 或更高版本时,这才是正确的方法(我通过查看问题标签来假设。如果您想使用较低的 iOS 版本,则必须实现UIAlertViewDelegate protocol 并更改您的功能。我现在不会详细说明,但如果您确实计划部署到 iOS

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2010-11-11
    相关资源
    最近更新 更多