0

コードでカスタムキーボードを作成します。self.inputView で、カスタム コンテンツを入力するためのボタンをいくつか追加します。コアコードは次のとおりです。

[self.wordsSenders enumerateObjectsUsingBlock:^(UIButton * _Nonnull cell, NSUInteger idx, BOOL * _Nonnull stop) {
    [self.inputView addSubview:cell];
}];

すべてのボタンを正確に表示できます。iOS 10 では、inputViewController はボタンのアクションに応答して単語を入力できます。しかし、iOS 8.2 または iOS 9.3 では、認識されないセレクターが 0xXXXX に送信されるため、ボタンを押すとクラッシュします。MeanWhile、オブジェクト、受信ボタンのアクションが異なります。inputViewControllerinputWord:はトリガーではありません!

- (void)inputWord:(UIButton *)sender {
if ([sender.titleLabel.text isEqualToString:@"字"]) {
    _showSpecialWords = !_showSpecialWords;

    for (int i = 20; i < 28; i ++) {
        if (_showSpecialWords) {
            [self.wordsSenders[i] setTitle:self.specialWords[i - 20] forState:UIControlStateNormal];
        } else {
            [self.wordsSenders[i] setTitle:self.normalWords[i] forState:UIControlStateNormal];
        }
    }
} else {
    [self.textDocumentProxy deleteBackward];
    [self.textDocumentProxy insertText:sender.titleLabel.text];
}
}

ボタン バインド アクションの場合:

[cell addTarget:self action:@selector(inputWord:) forControlEvents:UIControlEventTouchUpInside];

何か助けはありますか?ありがとう!

4

1 に答える 1