gpt4 book ai didi

ios - 通过快速警报更改屏幕

转载 作者:行者123 更新时间:2023-11-28 07:13:24 25 4
gpt4 key购买 nike

我不知道如何以编程方式更改屏幕。我有一个警报 View ,我希望能够在用户按下“确定”按钮时更改屏幕。我该怎么做?

这是我的新代码:

func showAlertController(){
let tilte = "My Medication"
let message = NSLocalizedString("Go through Medication guide?", comment: "")
let cancelButtonTitle = NSLocalizedString("Dismiss", comment: "")
let otherButtonTitle = NSLocalizedString("Ok", comment: "")

let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)



let cancelAction = UIAlertAction(title: cancelButtonTitle, style: .Cancel){ action in
NSLog("User said no")}

let otherAction = UIAlertAction(title: otherButtonTitle, style: .Default){action in
// I know I need to put something in here.
let appointment = Appointment()
self.presentViewController(appointment, animated:true, completion:nil)
}

alertController.addAction(cancelAction)
alertController.addAction(otherAction)

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

}

但是现在我得到一个错误说:线程 1:EXC_BAD_INSTRUCTION(code=EXC_l1386_INVOP,subcode=0x0)

最佳答案

在 UIAlertAction 闭包中为“Ok”按钮添加 presentViewController,这意味着按钮已按下,因此您可以为 block 内按下的按钮做一些事情。

class MainViewController: UIViewController {
...
...
func showAlertController(){
let tilte = "My Medication"
let message = NSLocalizedString("Go through Medication guide?", comment: "")
let cancelButtonTitle = NSLocalizedString("Dismiss", comment: "")
let otherButtonTitle = NSLocalizedString("Ok", comment: "")

let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)



let cancelAction = UIAlertAction(title: cancelButtonTitle, style: .Cancel){ action in
NSLog("User said no")}

let otherAction = UIAlertAction(title: otherButtonTitle, style: .Default){action in
// I know I need to put something in here.
let appointmentViewController = AppointmentViewController()
self.presentViewController(appointmentViewController, animated:true, completion:nil)
}

alertController.addAction(cancelAction)
alertController.addAction(otherAction)

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

}
...
...
}

class AppointmentViewController: UIViewController {

}

关于ios - 通过快速警报更改屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27489858/

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