【问题标题】:switch statement assign to NSlocalizedStringswitch 语句分配给 NSlocalizedString
【发布时间】:2016-09-20 14:04:04
【问题描述】:

如何将updateHeaderNotifications 和DebugAlert 分配给NSlocalizedString?我尝试添加updateHeaderNotifications = Nslocalized("text_text"),但它不起作用。感谢帮助

private func initViewToCurrentState(pocketStatus: pocketStatus?) {
    if let status = pocketStatus {
        switch status {
        case .Created:
            **updateHeaderNotifications** ("text1")
            initpocketBeforeTripView()

        case .Paid: fallthrough
        case .Undone: fallthrough
        case .Aborted: fallthrough
        default:
            PocketRideService.sharedInstance.removeCachedRide()
            dismissViewControllerAnimated(false, completion: {
                DebugAlert.show("text")

            })
        }
    }
}

【问题讨论】:

  • updateHeaderNotifications是如何定义的?

标签: iphone swift switch-statement case


【解决方案1】:

根据您的方法定义,您可以像下面这样使用:

private func updateHeaderNotifications(bigNotify: String, smallNotify: String) {
    bigNotification.text = NSLocalizedString(bigNotify, comment: "bigNotify")//you can set any text for comment parameter
    smallNotification.text = NSLocalizedString(smallNotify, comment: "smallNotify")
}

在您的switch 声明中:

        case .Created:
        updateHeaderNotifications("text1", smallNotify: "text2")

【讨论】:

  • 我可以那样做吗?
  • case .Created: updateHeaderNotifications(NSLocalizedString("AA_AA"), NSLocalizedString("AA_AA2")) initRouteBeforeTripView())
  • NSLocalizedString,需要两个参数。是的,您可以尝试在 switch 本身中设置文本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-15
  • 2021-04-26
  • 1970-01-01
  • 2015-09-25
相关资源
最近更新 更多