我有以下代码
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,但当我单击一个按钮时,它不会调用处理程序函数。有什么想法吗?
发布于 2015-11-08 06:37:16
你可以试试这段代码。
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
}发布于 2016-01-18 09:07:37
对于国际化,您具有以下条件:
title: "retry".localized,尝试将其更改为类似以下内容:
title: (NSLocalizedString("retry" , comment: "Retry something.") as String),您可以对所有其他要国际化的字符串执行相同的操作,在您提供的代码中,它们是您在前面放入".localized“的字符串。
当然,捆绑包中必须已将Localizable.strings文件设置为所需的语言。如果你需要,在How to localize my app with Xcode 4?上有更多关于它的信息
祝好运。
https://stackoverflow.com/questions/33587137
复制相似问题