首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UIAlertController不适用于Swift 3.0

UIAlertController不适用于Swift 3.0
EN

Stack Overflow用户
提问于 2016-10-15 13:49:32
回答 3查看 31.7K关注 0票数 18

我有以下的警告方法。

代码语言:javascript
复制
static func notifyUser(_ title: String, message: String) -> Void
{
    let alert = UIAlertController(title: title,
                                  message: message,
                                  preferredStyle: UIAlertControllerStyle.alert)

    let cancelAction = UIAlertAction(title: "OK",
                                     style: .cancel, handler: nil)

    alert.addAction(cancelAction)
    self.presentViewController(alert, animated: true, completion: nil)
}

我得到一个错误,告诉我在presentViewController方法中有一个额外的参数animated,但是当我取出它时,它仍然没有忽略这个错误,然后我被告知completion是一个额外的参数。

EN

回答 3

Stack Overflow用户

发布于 2016-10-15 13:53:53

代码语言:javascript
复制
 let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Swiftly Now! Choose an option!", preferredStyle: .alert)
 let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
            //Just dismiss the action sheet
        }
 actionSheetController.addAction(cancelAction)
 self.present(actionSheetController, animated: true, completion: nil)
票数 27
EN

Stack Overflow用户

发布于 2017-05-13 12:08:21

Swift 3

代码语言:javascript
复制
let alertView = UIAlertController(title: "", message: "your message", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: { (alert) in

})
alertView.addAction(action)
self.present(alertView, animated: true, completion: nil)
票数 11
EN

Stack Overflow用户

发布于 2018-04-23 18:09:10

代码语言:javascript
复制
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
if action {
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: {
        (action : UIAlertAction!) in self.navigationController?.popViewController(animated: true)
    }))
} else {
    alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
}
self.present(alert, animated: true, completion: nil)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40055488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档