我是菜鸟,所以如果这个问题很简单,请原谅我。
我创建了一个UIActionSheet,弹出多个选项,并根据用户选择的内容我想要更新动态标签。我知道如何制作标签,但我无法弄清楚我缺少什么来更新标签。任何人都可以帮我解决我应该添加的内容吗?
我的代码如下:
@IBAction func button(sender: UIButton) {
let alertController = UIAlertController(title: "Title", message: "", preferredStyle: .ActionSheet)
let oneAction = UIAlertAction(title: "A", style: .Default) { (_) in }
let twoAction = UIAlertAction(title: "B", style: .Default) { (_) in }
let threeAction = UIAlertAction(title: "C", style: .Default) { (_) in }
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
// ...
}
alertController.addAction(oneAction)
alertController.addAction(twoAction)
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true) {
}
答案 0 :(得分:0)
只需更新处理程序中的标签即可。这样的事情。
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
// ...
self.theLabel.text = "Cancel"
}
答案 1 :(得分:0)
您可以在UIAlertAction
:
@IBAction func button(sender: UIButton)
{
let alertController = UIAlertController(title: "Title", message: "", preferredStyle: .ActionSheet)
let oneAction = UIAlertAction(title: "A", style: .Default) { (_) in
// Update Label here
yourLabel.text = "A"
}
let twoAction = UIAlertAction(title: "B", style: .Default) { (_) in
// Update Label here
yourLabel.text = "B"
}
let threeAction = UIAlertAction(title: "C", style: .Default) { (_) in
// Update Label here
yourLabel.text = "C"
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
// Update Label here
yourLabel.text = "Cancel Clicked"
}
alertController.addAction(oneAction)
alertController.addAction(twoAction)
alertController.addAction(threeAction)
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true) {
}
}