質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

1回答

1216閲覧

【Swift】カスタムキーボードが表示されない

cocona15531

総合スコア6

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2021/04/07 09:42

編集2021/04/09 04:22

前提・実現したいこと

Swift初心者です。
raywenderrich.comの記事を参考にさせて頂きながらカスタムキーボードを開発中です。

発生している問題・エラーメッセージ

参考にさせて頂いているraywenderlich.comの記事のStarterファイルをビルドしてみたのですが、下図のように何も表示されず、エラーが出てしまいました。新たに作成したカスタムキーボード拡張機能のSwiftファイル(keyboardviewcontroller.swift)と連携ができていないのかもしれないです。どなたかご回答して頂きたいです。下にファイル構成のスクショも貼っておきます。

MorseKeyboard[59137:6509431] [External] -[UIInputViewController needsInputModeSwitchKey] was called before a connection was established to the host application. This will produce an inaccurate result. Please make sure to call this after your primary view controller has been initialized.

イメージ説明

イメージ説明

keyboardviewcontroller.swift

swift

1/// Copyright (c) 2021 Razeware LLC 2/// 3/// Permission is hereby granted, free of charge, to any person obtaining a copy 4/// of this software and associated documentation files (the "Software"), to deal 5/// in the Software without restriction, including without limitation the rights 6/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7/// copies of the Software, and to permit persons to whom the Software is 8/// furnished to do so, subject to the following conditions: 9/// 10/// The above copyright notice and this permission notice shall be included in 11/// all copies or substantial portions of the Software. 12/// 13/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, 14/// distribute, sublicense, create a derivative work, and/or sell copies of the 15/// Software in any work that is designed, intended, or marketed for pedagogical or 16/// instructional purposes related to programming, coding, application development, 17/// or information technology. Permission for such use, copying, modification, 18/// merger, publication, distribution, sublicensing, creation of derivative works, 19/// or sale is expressly withheld. 20/// 21/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27/// THE SOFTWARE. 28 29import UIKit 30 31class KeyboardViewController: UIInputViewController { 32 33 @IBOutlet var nextKeyboardButton: UIButton! 34 35 override func updateViewConstraints() { 36 super.updateViewConstraints() 37 38 // Add custom view sizing constraints here 39 } 40 41 override func viewDidLoad() { 42 super.viewDidLoad() 43 44 // Perform custom UI setup here 45 self.nextKeyboardButton = UIButton(type: .system) 46 47 self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), for: []) 48 self.nextKeyboardButton.sizeToFit() 49 self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false 50 51 self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents) 52 53 self.view.addSubview(self.nextKeyboardButton) 54 55 self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true 56 self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true 57 } 58 59 override func viewWillLayoutSubviews() { 60 self.nextKeyboardButton.isHidden = !self.needsInputModeSwitchKey 61 super.viewWillLayoutSubviews() 62 } 63 64 override func textWillChange(_ textInput: UITextInput?) { 65 // The app is about to change the document's contents. Perform any preparation here. 66 } 67 68 override func textDidChange(_ textInput: UITextInput?) { 69 // The app has just changed the document's contents, the document context has been updated. 70 71 var textColor: UIColor 72 let proxy = self.textDocumentProxy 73 if proxy.keyboardAppearance == UIKeyboardAppearance.dark { 74 textColor = UIColor.white 75 } else { 76 textColor = UIColor.black 77 } 78 self.nextKeyboardButton.setTitleColor(textColor, for: []) 79 } 80 81} 82

試したこと

上図のファイル構成の画像にもある通り、Target Membershipのところが原因かもしれないと思い、切り替えて見ましたが解決できませんでした。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

中に何も表示されていませんが、それでも表示されているのはあなたの作成したキーボードのように思われます。そうであれば、そのエラーメッセージはキーボードの中が表示されない原因を示しているわけではなさそうなので、一旦置いておきましょう。

単に表示の問題のように思われます。
XcodeのDebug View Hierarchyボタンなどを使って制約が正しくついているか、ビュー階層は意図したとおりか、などの表示系の問題の追求をするとよいのではないでしょうか。

なお、viewWillLayoutSubviewsの中で設定しているisHiddenがfalseになっているかどうかを、まず、確認してみた方が良いように思います。

投稿2021/04/09 15:14

eytyet

総合スコア803

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問