- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter]; [nCenter addobserver:self selector:@selector(languageChanged:) name:UITextinputCurrentinputModeDIDChangeNotification object:nil]; [self languageChanged:nil];}-(voID)languageChanged:(NSNotification*)notification{ for(UITextinputMode *mode in [UITextinputMode activeinputModes]) { NSLog(@"input mode: %@",mode); NSLog(@"input language: %@",mode.primaryLanguage); } NSLog(@"Notification: %@",notification); UITextinputMode *current = [UITextinputMode currentinputMode]; NSLog(@"Current: %@",current.primaryLanguage);}
我们用这段代码发现的是当用户使用键盘上的地球图标切换键盘时,通知会正确触发,但是当我们迭代UITextinputModes时,它们以相同的顺序出现,没有(明显)指示哪个是当前的一个,除非我们使用现已弃用的[UITextinputMode currentinputMode].
我找不到任何文档表明Apple建议替代现已弃用的功能.有几个SO线程提到了弃用,但我找不到解决方案.有任何想法吗?提前致谢.
解决方法 通知UITextinputCurrentinputModeDIDChangeNotification的对象是UITextinputMode的实例.UITextinputMode *currentinputMode = [notification object];
此外,您可以在特定响应者上获得活动输入模式:
UITextVIEw *textVIEw = [[UITextVIEw alloc] init];UITextinputMode *currentinputMode = textVIEw.textinputMode;
目前在iOS 7上,表情符号键盘的textinputMode / notification对象为nil.目前还不清楚这是否是预期的行为.
总结以上是内存溢出为你收集整理的ios – 不推荐使用UITextInputMode currentInputMode.建议更换?全部内容,希望文章能够帮你解决ios – 不推荐使用UITextInputMode currentInputMode.建议更换?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)