I build a custom keyboard by codes. On the self.inputView, add some buttons to input custom content. the core codes as follows:
[self.wordsSenders enumerateObjectsUsingBlock:^(UIButton * _Nonnull cell, NSUInteger idx, BOOL * _Nonnull stop) {
[self.inputView addSubview:cell];
}];
all buttons can display exactly. In iOS 10, inputViewController can response button's action to input word. but in iOS 8.2 or iOS 9.3, press button will lead to crash because unrecognized selector send to 0xXXXX. MeanWhile, the object, receive button's action, is different. the inputViewController's inputWord:
isn't trigger!
- (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];
}
}
for button binding action:
[cell addTarget:self action:@selector(inputWord:) forControlEvents:UIControlEventTouchUpInside];
Any help? Thanks!
Oh, sorry, It's my mistake! I should maintain a instance variable about
UIInputViewController
rather than build a local variable. In iOS 10, it can work exactly It may be because system automaticly maintainUIInputViewController
instance and iOS 8 or iOS 9 doesn't. just like this: