swift 3

时间:2017-03-09 04:04:24

标签: swift3 uialertview uialertcontroller uiactionsheet uialertaction

当我按下按钮时,我想选择包装类型。
包装有 三种

1. 打包A
2. 套餐B
3. 包C

enter image description here

我对如何实现这个过程很困惑。我不确切地知道它应该是警报框还是行动表?我不清楚这一点。上面的图片是行动表,不是吗?
但是,我发现iOS 8及更高版本已经弃用了动作表样式。那么,我不能用这个?你能否解释一下快速行动表和警报框之间的区别。   谢谢。

1 个答案:

答案 0 :(得分:1)

可以使用UIAlertController创建操作表和警报: 要创建一个Action Sheet,您必须创建一个UIAlertController实例并向其添加操作: -

let actionSheet = UIAlertController(title: "Choose Package Type", message: nil , preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Package A", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Package B", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Package C", style: .default, handler: nil ))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel , handler: {
                (action: UIAlertAction) -> Void in
                actionSheet.dismiss(animated: true, completion: nil)
            }))
 present( actionSheet , animated:  true , completion:  nil)

您可以根据您的任务替换处理程序并替换为#selector。