gpt4 book ai didi

ios - 如何在 ActionSheet 中使用 if/else 语句?

转载 作者:行者123 更新时间:2023-11-28 08:45:05 25 4
gpt4 key购买 nike

在我正在创建的应用程序中,我有一个带有一些选项的 ActionSheet。当用户选择一个选项时,我希望标签更改为他/她选择的内容。我尝试了 if/else 语句,但显然我没有正确创建它-


@IBAction func showActionSheet(sender: AnyObject) {

var optionMenu = UIAlertController(title: nil, message: "Choose a Factor", preferredStyle: .ActionSheet)


let factorActionCageRest = UIAlertAction(title: "Cage Rest", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("File Deleted")
})

let factorActionAfterSurgery = UIAlertAction(title: "After Surgery", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("File Saved")
})

let factorActionTrauma = UIAlertAction(title: "Trauma", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("File Saved")
})

let factorActionSepsis = UIAlertAction(title: "Sepsis", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("File Saved")
})

let factorActionSevereBurn = UIAlertAction(title: "Severe Burn", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("File Saved")
})

let factorCancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})


optionMenu.addAction(factorActionCageRest)
optionMenu.addAction(factorActionAfterSurgery)
optionMenu.addAction(factorActionTrauma)
optionMenu.addAction(factorActionSepsis)
optionMenu.addAction(factorActionSevereBurn)
optionMenu.addAction(factorCancelAction)

if optionMenu.addAction() = factorActionCageRest {
var factorActionOutput = 1.25
factorLabel.text = "\(factorActionOutput)"
}
self.presentViewController(optionMenu, animated: true, completion: nil)

}

@IBOutlet weak var factorLabel: UILabel!
var factorActionOutput = Float()


}

问题- 如何将 if/else 语句应用于用户的选项?谢谢!

最佳答案

更新您的 UIAlertAction 处理程序以包含用于更改标签的代码。

let factorActionCageRest = UIAlertAction(title: "Cage Rest", style: .Default, handler: {
[weak self] (alert: UIAlertAction!) -> Void in
print("File Deleted")
let factorActionOutput = 1.25
self?.factorLabel.text = "\(factorActionOutput)"
})

关于ios - 如何在 ActionSheet 中使用 if/else 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35532632/

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