UIAlertController斯威夫特
问题描述:
我有以下代码UIAlertController斯威夫特
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)
的对话框显示正常,但是当我点击一个按钮,它不会调用处理函数。任何想法?
答
您可以试试这段代码。
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
}
答
对于国际化,你必须:
title: "retry".localized,
尝试改变它像:
title: (NSLocalizedString("retry" , comment: "Retry something.") as String),
您可以为所有要国际化的其他琴弦做同样的,在您提交的代码中,它们是您在前面放入“.localized
”的字符串。
当然你必须在你的包中有Localizable.strings文件已经设置为你想要的语言。如果您需要更多关于它的地方How to localize my app with Xcode 4?
祝您好运。
你说的是点击'retry'按钮吗? –
这两个按钮都不起作用 – Yamila
您是否尝试添加断点或日志记录以查看它是否至少到达那里?可能听起来很愚蠢,但这将是第一步。 –