加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift中UIActionSheet的使用

发布时间:2020-12-14 02:33:30 所属栏目:百科 来源:网络整理
导读:// 方法1let alertSheet = UIActionSheet(title: alertTitle,delegate: nil,cancelButtonTitle: alertOK,destructiveButtonTitle: alertCancel)alertSheet.showInView(self.view) // 方法2// 实例化时添加代理对象,同时注意添加协议let alertSheet = UIActi
// 方法1
let alertSheet = UIActionSheet(title: alertTitle,delegate: nil,cancelButtonTitle: alertOK,destructiveButtonTitle: alertCancel)
alertSheet.showInView(self.view)


// 方法2
// 实例化时添加代理对象,同时注意添加协议
let alertSheet = UIActionSheet(title: alertTitle,delegate: self,destructiveButtonTitle: alertCancel,otherButtonTitles: "警告","提示","通告")
alertSheet.showInView(self.view)
// 添加协议
class ViewController: UIViewController,UIActionSheetDelegate {
    
    override func viewDidLoad() {
        ...
    }
    ...
}
// 代理方法
// MARK: UIActionSheetDelegate
func actionSheet(actionSheet: UIActionSheet,clickedButtonAtIndex buttonIndex: Int) {
        let buttonTitle = actionSheet.buttonTitleAtIndex(buttonIndex)
        if buttonTitle == alertCancel
        {
            print("你点击了退出")
        }
        else if buttonTitle == alertOK
        {
            print("你点击了确定")
        }
        else
        {
            print("你点击了其他")
        }
}
// 方法3
// 1 实例化
let alertSheet = UIAlertController(title: alertTitle,message: alertMessage,preferredStyle: UIAlertControllerStyle.ActionSheet)
// 2 命令(样式:退出Cancel,警告Destructive-按钮标题为红色,默认Default)
let cancelAction = UIAlertAction(title: alertCancel,style: UIAlertActionStyle.Cancel,handler: nil)
let deleteAction = UIAlertAction(title: "删除",style: UIAlertActionStyle.Destructive,handler: nil)
let archiveAction = UIAlertAction(title: alertOK,style: UIAlertActionStyle.Default,handler: {
            action in
            print("OK")
})
alertSheet.addAction(cancelAction)
alertSheet.addAction(deleteAction)
alertSheet.addAction(archiveAction)
// 3 跳转
self.presentViewController(alertSheet,animated: true,completion: nil)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读