我正在尝试使用 Swift 制作一个简单的 iOS 自定义键盘扩展。默认的 UIView 不能满足我的需求,所以我阅读了 this所以问题是我可以在 info.plist
中使用带有 NSExtensionMainStoryboard
属性的 Storyboard。
不幸的是,每次我打开键盘时,我都会收到以下错误
2016-01-18 18:02:56.350 Kappa Keyboard[44790:2959180] Failed to inherit CoreMedia permissions from 44787: (null)
2016-01-18 18:02:56.368 Kappa Keyboard[44790:2959138] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x002f1746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01d32a97 objc_exception_throw + 44
2 CoreFoundation 0x001a6ce1 -[__NSArrayM insertObject:atIndex:] + 881
3 CoreFoundation 0x001a6941 -[__NSArrayM addObject:] + 65
4 UIKit 0x00c7d0bd -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 417
5 UIKit 0x00c968aa -[UIViewController(UIContainerViewControllerProtectedMethods) addChildViewController:] + 78
6 UIKit 0x01206db8 -[_UIViewServiceViewControllerOperator __createViewController:withContextToken:fbsDisplays:appearanceSerializedRepresentations:legacyAppearance:traitCollection:initialInterfaceOrientation:hostAccessibilityServerPort:canShowTextServices:replyHandler:] + 2702
堆栈跟踪继续,但这就是它的要点。
这是我所做的一切(我在一个干净的项目中尝试过)。
- 创建容器应用
- 创建键盘目标
- 添加主 Storyboard
- 添加
NSExtension.NSExtensionMainStoryboard: Main
到 info.plist - 将
Main.storyboard
的自定义类设置为默认的KeyboardViewController
知道我错过了什么吗?
最佳答案
将 Storyboard文件添加到您的键盘目标。
在您的键盘目标的常规选项卡中,将 Main Interface
创建到您的 Storyboard文件,如屏幕截图所示。
第二个重要部分是确保将 KeyboardViewController
引用的 View 类更改为 UIInputView
而不是 Storyboard中的 UIView
。
关于带有 Storyboard的 iOS 自定义键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866443/