首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAlertController Swift

UIAlertController Swift
EN

Stack Overflow用户
提问于 2015-11-08 03:59:38
回答 2查看 956关注 0票数 2

我有以下代码

代码语言:javascript
复制
let alertController = UIAlertController(title: "error_title".localized, message: "error".localized, preferredStyle: .ActionSheet)

    let retryAction = UIAlertAction(
        title: "retry".localized,
        style: .Default,
        handler: {
            (action:UIAlertAction!) in
            self.fetch()
        }
    )
    alertController.addAction(retryAction)

    let cancelAction = UIAlertAction(
        title: "cancel".localized,
        style: .Default,
        handler: {
            (action:UIAlertAction!) in
            self.navigationController!.popViewControllerAnimated(true)
        }
    )
    alertController.addAction(cancelAction)

    self.presentViewController(alertController, animated: true, completion: nil)

对话框显示为ok,但当我单击一个按钮时,它不会调用处理程序函数。有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2015-11-08 06:37:16

你可以试试这段代码。

代码语言:javascript
复制
let alertController = UIAlertController(title: "AlertCotrol", message: "A standard alert.", preferredStyle: .Alert)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
// ... Do something 
}
alertController.addAction(cancelAction)

let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
// ... Do something 
}
alertController.addAction(OKAction)

self.presentViewController(alertController, animated: true) {
// ... Do something 
}
票数 0
EN

Stack Overflow用户

发布于 2016-01-18 09:07:37

对于国际化,您具有以下条件:

代码语言:javascript
复制
title: "retry".localized,

尝试将其更改为类似以下内容:

代码语言:javascript
复制
title: (NSLocalizedString("retry" , comment: "Retry something.") as String),

您可以对所有其他要国际化的字符串执行相同的操作,在您提供的代码中,它们是您在前面放入".localized“的字符串。

当然,捆绑包中必须已将Localizable.strings文件设置为所需的语言。如果你需要,在How to localize my app with Xcode 4?上有更多关于它的信息

祝好运。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33587137

复制
相关文章

相似问题

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