【发布时间】:2016-02-03 03:47:45
【问题描述】:
我在 Swift (iOS 8+) 中有一个方便的方法来显示错误消息。到目前为止,它看起来像这样:
// Supplied with a category code and an error code, generates an error dialogue box.
// Codes rather than strings because this needs to be localisable.
func showErrorDialogue(categoryCode: String, _ errorCode: String) -> () {
// Fetch the actual strings from the localisation database.
let localisedCategory = NSLocalizedString(categoryCode, comment: categoryCode)
let localisedError = NSLocalizedString(errorCode, comment: errorCode)
// Create an alert box
let alertController = UIAlertController(
title: localisedCategory,
message: localisedError,
preferredStyle: .Alert
)
alertController.addAction(
UIAlertAction(
title: "OK", // FIXME: why isn't this localised?
style: .Default,
handler: { (action) in return }
)
)
self.presentViewController(alertController, animated: true) { return }
}
我不能只说“我只在此警报框中添加一个按钮,所以请假设它将是区域设置默认的确定按钮”,这似乎很奇怪。到目前为止,我通过有限的谷歌搜索找到的最佳解决方案似乎是Steal them from the System and hope,这有点狡猾。
【问题讨论】:
标签: ios swift localization