首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用哪个标识符来代替“在场”?

使用哪个标识符来代替“在场”?
EN

Stack Overflow用户
提问于 2017-11-24 06:31:32
回答 2查看 910关注 0票数 1

当我在当前警报行中使用警告时,我会得到这个错误,使用未解决的标识符。

文件名:CommonFunctions.swift

类名:类CommonFunctions : NSObject

我正在使用这个代码

代码语言:javascript
运行
复制
class func gotoSettingScreen()
{
    let alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .alert)

    let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
        guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
            return
        }

        if UIApplication.shared.canOpenURL(settingsUrl) {
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                    print("Settings opened: \(success)") // Prints true
                })
            } else {
                // Fallback on earlier versions
            }
        }
    }
    alertController.addAction(settingsAction)
    let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
    alertController.addAction(cancelAction)


    present(alertController, animated: true, completion: nil)
}

行错误来:present(alertController, animated: true, completion: nil)

错误是:

谢谢你的帮助!还有欣赏!

EN

Stack Overflow用户

发布于 2018-10-08 11:14:34

如果您想使用来自非uiview控制器的警报,可以传递uiviewcontroller实例表单方法,如

方法在NonUicontroller类中的应用

代码语言:javascript
运行
复制
func alertDilog(viewController :UIViewController)
{
   let alertController = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
            (result : UIAlertAction) -> Void in
            print("OK")
   alertController.addAction(okAction)
        vc.present(alertController, animated: true, completion: nil)
    }
        }

在UiViewcontrollerclass中使用alertDialog

代码语言:javascript
运行
复制
yourclassName.alertDilog(viewController :self)
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47467537

复制
相关文章

相似问题

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