gpt4 book ai didi

ios - UITableViewSection footerTitle 未本地化

转载 作者:行者123 更新时间:2023-11-29 12:18:53 30 4
gpt4 key购买 nike

我已将丹麦语本地化添加到我的 iOS 8 项目中。我想本地化静态 UITableViewSection 的页眉和页脚,我面临的问题是页眉已本地化,但页脚始终包含来自 Main.strings(英语)文件的字符串。这些值是通过 Interface Builder 设置的。我已经在设备和模拟器上对此进行了测试。

Main.strings(英文)

/* Class = "UITableViewSection"; footerTitle = "..."; ObjectID = "cHU-BB-3aF"; */
"cHU-BB-3aF.footerTitle" = "Footer Title";

/* Class = "UITableViewSection"; headerTitle = "Payment Details"; ObjectID = "cHU-BB-3aF"; */
"cHU-BB-3aF.headerTitle" = "Header Title";

Main.strings(丹麦语)

/* Class = "UITableViewSection"; footerTitle = "..."; ObjectID = "cHU-BB-3aF";*/
"cHU-BB-3aF.footerTitle" = "Localized Footer Title"; // this does not work

/* Class = "UITableViewSection"; headerTitle = "Payment Details"; ObjectID = "cHU-BB-3aF"; */
"cHU-BB-3aF.headerTitle" = "Localized Header Title"; // this works

最佳答案

您可以在代码中设置页脚的标题并改用 NSLocalizedString。要在代码中设置页脚的标题,您应该实现 tableView:viewForFooterInSection:。所以,它看起来像这样:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerLabel = UILabel(frame: CGRect.zeroRect)
footerLabel.text = NSLocalizedString("Your title for footer", comment: "Comment for footer")
footerLabel.sizeToFit()
return footerLabel
}

然后您可以在终端中使用genstrings 命令创建一个Localizable.strings 文件:

  1. 打开终端并 cd 到包含您的项目的文件夹
  2. 键入此命令:genstrings *.swift -o en.lproj
  3. 将 Localizable.strings 文件添加到您的项目

您可以通过在项目导航器中选择它,在实用程序中选择文件检查器,然后选中丹麦语来添加丹麦语的 Localizable.strings 文件的本地化。

关于ios - UITableViewSection footerTitle 未本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31248210/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com