在我正在创建的应用程序中,我有一个带有一些选项的操作表。当用户选择一个选项时,我希望标签更改为他/她选择的内容。我尝试了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/