gpt4 book ai didi

ios - 获取当前事件的键盘语言作为 NSLocale

转载 作者:行者123 更新时间:2023-11-28 09:46:35 34 4
gpt4 key购买 nike

我已经找到了很多方法来解决这个问题,但没有有效的解决方案。这是我尝试过但没有奏效的方法。

(1) 只需调用primaryLanguage()

UITextInputMode().primaryLanguage

→ 总是返回 nil :-/

(2) 订阅UITextInputCurrentInputModeDidChangeNotification通知

override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil)
}

func changeInputMode(sender : NSNotification) {
...?!
}

通知已被触发,但不清楚如何从通知中提取当前语言信息。

(3) 使用activeInputModes()

let localeIdentifier = UITextInputMode.activeInputModes().first as? UITextInputMode
var locale:NSLocale = NSLocale(localeIdentifier: localeIdentifier.primaryLanguage!)
println("Input Mode Language \(localeIdentifier.primaryLanguage!)")

这总是提供所有可用键盘的相同数组,没有关于实际事件键盘的信息。

如何获取当前事件键盘的 NSLocale?

最佳答案

您可以通过访问文本字段 textInputMode 来从每个文本字段访问 primaryLanguage:

var language = textfield.textInputMode?.primaryLanguage

关于ios - 获取当前事件的键盘语言作为 NSLocale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28682576/

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