ios - UITableViewSection footerTitle 未本地化

标签 ios uitableview localization

我已将丹麦语本地化添加到我的 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/

相关文章:

java - 如何在ios上将用户1的位置跟踪信息推送给用户2

ios - 如何以编程方式将其添加到NSMutableArray并将其显示在表格 View 单元格上?

localization - 当我向文件名添加文化时,我的全局资源设计器文件为空

swift - 如何在子类中覆盖 tableView 样式

iphone - iPhone 中图标和默认屏幕的本地化

c++ - 设计字符串本地化的最佳方法

iOS 设置 MKMapView 中心所以提供的位置在底部中心

ios - AvPlayer streaming,所有元数据信息都在timedMetadata里?

iOS isKindOfClass 和 isMemberOfClass 之间的区别

iphone - 触摸嵌入 View 时选择表格单元格