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

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

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

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

Q&A

解決済

1回答

1158閲覧

xcode でカスタムキーボード

shinya-ta

総合スコア31

Swift

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

0グッド

0クリップ

投稿2020/03/22 08:36

ボールドテキストカスタムキーボードを作ろうとしています。
書籍を見ながら書いてますが、エラーの山だらけで、何が悪いか判りません。
どなたか助言をお願いします。```import UIKit

class KeyboardViewController: UIInputViewController {

@IBOutlet var nextKeyboardButton: UIButton! override func updateViewConstraints() { super.updateViewConstraints() // Add custom view sizing constraints here } override func viewDidLoad() { super.viewDidLoad() var v = UINib(nibName:"keyboardView", bundle:nil).instantiateWithOwner(self,options:nil)[0] as UIView self.inputView.addSubview(v) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated } override func textWillChange(textInput: UITextInput) { // The app is about to change the document's contents. Perform any preparation here. } override func textDidChange(textInput: UITextInput) { // The app has just changed the document's contents, the document context has been updated. } @IBAction func buttonNext(sender: AnyObject) { self.advanceToNextInputMode() } @IBAction func button1(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button1") } @IBAction func button2(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button2") } @IBAction func button3(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button3") } @IBAction func button4(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button4") } @IBAction func button5(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button5") } @IBAction func button6(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button6") }

}

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

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

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

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

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

thyda.eiqau

2020/03/22 09:10

その「エラーの山」が、何が悪いかを示していますので、1つずつ確認してエラーが出ないように修正してください。修正方法がわからないものがあれば、そのエラーをご提示ください。
shinya-ta

2020/03/22 15:16

var v = UINib(nibName:"keyboardView", bundle:nil).instantiateWithOwner(self,options:nil)[0] as UIView ↑で↓のエラーが出ます。 'Any' is not convertible to 'UIView'; did you mean to use 'as!' to force downcast? override func textWillChange(textInput: UITextInput) { ↑で↓のエラーが出ます。 Argument labels for method 'textWillChange(textInput:)' do not match those of overridden method 'textWillChange' @IBAction func button1(sender: AnyObject) { var proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText("Button1" 各ボタンのところのvar proxy = textDocumentProxy as UITextDocumentProxy というところにVariable 'proxy' was never mutated; consider changing to 'let' constant が出ます。
hoshi-takanori

2020/03/22 19:34

参考にしている書籍を教えてください。(古い本だと、今の Swift に対応できてない可能性が高いので。)
shinya-ta

2020/03/23 06:22

「小学生でもわかるiPhoneアプリの作り方」を参考に、あとネットの状態を元に、付け足してました。
shinya-ta

2020/03/23 09:58

状態ではなく、情報の間違いです。すみません。
hoshi-takanori

2020/03/23 10:16

その本にはカスタムキーボードの作り方は載ってないみたいですけど…。まぁいいや。 とりあえず as は as! にして、textWillChange(textInput: UITextInput) は textInput の前に _ を入れて textWillChange(_ textInput: UITextInput) にすればいいのでは。
shinya-ta

2020/03/23 23:13

as!にしてもエラーの数が増えるだけでした。_も同様です。
thyda.eiqau

2020/03/24 01:57

思うに、無からいきなりこのコード量になるとは考えられないので、最初はKeyboard Extensionのプロジェクトを作って (プロジェクトを作ってからKeyboard ExtensionのTargetを作るんだったかな?) まずその時点でビルドして動くか確認して、次にボタンを1つ追加して期待通りに動くかビルドして確認して、という手順を踏むと思うのですが、途中まで動いていて途中から動かなくなったのではないですかね? 動くところと動かないところの境界に原因があると思いますが、そこまでさかのぼって考えてみるとよいのではないでしょうか。
shinya-ta

2020/03/24 09:59

返答ありがとうございます。一度、遡って調べてみます。
guest

回答1

0

自己解決

別のコードを打ち直して、解決しました。ありがとうございました。

投稿2020/05/17 06:26

shinya-ta

総合スコア31

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問