gpt4 book ai didi

Swift 开关和 case 函数处理

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

我正在做一个开源项目,同时学习 swift,github 存储库位于 https://github.com/istx25/schedules。 .我正在尝试向案例添加一个标识符,每次在 UIActionSheet 中按下按钮时都会运行一个函数。 Action 表的代码如下:

@IBAction func rightButton(sender : AnyObject) {
var sheet: UIActionSheet = UIActionSheet()
let title: String = "Please choose a block rotation"
sheet.title = title
sheet.delegate = self
sheet.addButtonWithTitle("Cancel")
sheet.addButtonWithTitle("Day Four")
sheet.addButtonWithTitle("Day Three")
sheet.addButtonWithTitle("Day Two")
sheet.addButtonWithTitle("Day One")
sheet.cancelButtonIndex = 0
sheet.showInView(self.view)
}

并且我已经开始切换以延迟哪个按钮是:

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
switch buttonIndex {
case 0:
print("Go Back")
case 1:
print("Day Four")
// Day Four Function
case 2:
print("Day Three")
// Day Three Function
case 3:
print("Day Two")
// Day Two Function
case 4:
print("Day One")
// Day One Function
default:
print("Something's broken")
}
}

我希望每个案例都被推送到它自己的 func 方法,我不确定我将如何处理这个问题,所以如果有人能提供帮助,那就太好了。如果这个问题很难理解请告诉我;这样我就可以更好地在 Stackoverflow 上寻求帮助!提前致谢。

最佳答案

如果您的目标是 iOS 8,则不应使用 UIActionSheets,因为它们已被弃用。将 UIAlertController 与 UIAlertControllerStyleActionSheet 的 preferredStyle 一起使用,并使用 addAction() 方法向其添加操作。

关于Swift 开关和 case 函数处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26309821/

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