如何使用 UIActionSheet 选择更新动态标签?
How do I use UIActionSheet choice to update a dynamic label?
本人小白,问题简单还望见谅
我创建了一个 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) {
}
只需更新处理程序中的标签。像这样。
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
// ...
self.theLabel.text = "Cancel"
}
您可以在 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) {
}
}
本人小白,问题简单还望见谅
我创建了一个 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) {
}
只需更新处理程序中的标签。像这样。
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action) in
// ...
self.theLabel.text = "Cancel"
}
您可以在 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) {
}
}