带有 Storyboard的 iOS 自定义键盘

标签 ios iphone xcode swift keyboard

我正在尝试使用 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

堆栈跟踪继续,但这就是它的要点。

这是我所做的一切(我在一个干净的项目中尝试过)。

  1. 创建容器应用
  2. 创建键盘目标
  3. 添加主 Storyboard
  4. 添加 NSExtension.NSExtensionMainStoryboard: Main 到 info.plist
  5. Main.storyboard 的自定义类设置为默认的 KeyboardViewController

知道我错过了什么吗?

最佳答案

将 Storyboard文件添加到您的键盘目标。
在您的键盘目标的常规选项卡中,将 Main Interface 创建到您的 Storyboard文件,如屏幕截图所示。
第二个重要部分是确保将 KeyboardViewController 引用的 View 类更改为 UIInputView 而不是 Storyboard中的 UIView

enter image description here

关于带有 Storyboard的 iOS 自定义键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866443/

相关文章:

ios - UIimage 没有出现在 iOS 中的 ScrollView 上

iphone - 我可以使用越狱设备进行 iPhone 应用程序开发吗

ios - 当应用程序进入后台时,iOS 显示的图像在纵向模式下显示倒置

xcode - 在界面生成器中设计时自动布局 View 调整大小的挫折

ios - 仅在 XCode 6 上横向

ios - CGContextDrawImage (Swift) 上的间歇性 "incorrect checksum for freed object"错误

ios - 这是我的 HTTP POST 请求,但我成功获得了连接。它显示响应为空。如何纠正这个?

iphone - 如何反转 NSMutableArray 中的数据?

ios - Hook Music Player功能IOS 8

ios - AlamofireJson/EVReflection - NSArray 元素无法匹配中的 Swift 数组元素类型