这将解决..!
不要使用名称'inputAccessoryView
- (UIView *)CustominputAccessoryView {
if (!keyboardinputAccessoryView) {
CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0);
keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
keyboardinputAccessoryView.backgroundColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6];
UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom];
compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0);
[compButton setTitle: @"Done" forState:UIControlStateNormal];
compButton.titleLabel.textColor = [UIColor blueColor];
[compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal];
[compButton addTarget:self action:@selector(completeCurrentWord:)
forControlEvents:UIControlEventTouchUpInside];
[keyboardinputAccessoryView addSubview:compButton];
}
return keyboardinputAccessoryView;
}
keyboardinputAccessoryView 只是一个 UIView
@property (readonly, retain) UIView *keyboardinputAccessoryView;
然后将'CustominputAccessoryView'作为你的textField的inputAccessoryView
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.inputAccessoryView = [self CustominputAccessoryView];
}