-1

Have added a custom view consisting of buttons on top of the keyboard. The buttons are being displayed correctly but on tapping on the buttons, the underlying keys of the keyboard are pressed instead of the button actions.

UIWindow* tempWindow = [UIApplication sharedApplication].windows.lastObject;
for (UIView *keyboard in [tempWindow subviews]) {
    if ([[keyboard description] hasPrefix : @"<UIInputSetContainerView"]) {
    for(int i = 0 ; i < [keyboard.subviews count] ; i++)
       {
        UIView* hostkeyboard = [keyboard.subviews objectAtIndex:i];
        if([[hostkeyboard description] hasPrefix:@"<UIInputSetHost"] == YES){
            [hostkeyboard addSubview:extraRow];
            [hostkeyboard bringSubviewToFront:extraRow];
           }
       }
    }
}

extraRow is the UIView consisting of buttons.

Is there anything missing ?

jeff
  • 1
  • 3
  • 1
    Why don't you use `UITextField`'s and `UITextView`'s `inputAccessoryView` or `inputView` property? This seems wrong and (as you discovered) is easily broken. Wondering why this is even okay to do. – Tobi Nary Feb 01 '16 at 16:25
  • @JanGreve Want to have the view as an overlay above the keyboard and removed when needed keeping the keyboard intact. Is there any way to suppress the below and give priority for the above view ? Thank you for your response. – jeff Feb 02 '16 at 05:18
  • The keyboard is not considered part of your app; I doubt there is a way to legally (w.r.t. Apples rules) do that. – Tobi Nary Feb 02 '16 at 07:32

2 Answers2

0

You could do just add a custom view to the keyboard as an inputAccessoryView. Then it just assign the button the correct target you want it to fire when clicked on

- (void)textFieldDidBeginEditing:(UITextField *)textField {

    UIView  * theView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    [theView setBackgroundColor: [UIColor greyColor]];

    UITextField * txtTest = [[UITextField alloc] initWithFrame:CGRectMake(0, 5, theView.frame.size.width, 60)];
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 65, 100, 30)];

    [btn setTitle:@"Click my Button" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(alert:) forControlEvents:UIControlEventTouchUpInside];

    // Just put this to see the items or customize the color
    [txtTest setBackgroundColor:[UIColor whiteColor]];
    [btn setBackgroundColor:[UIColor blueColor]];

    // Need this to add it to the view
    [theView addSubview:txtTest];
    [theView addSubview:btn];

    textField.inputAccessoryView = theView;
}
Bryan Norden
  • 2,397
  • 18
  • 22
0

One thing you might want to consider is setting the extraRow's exclusiveTouch property to YES. As a disclaimer I haven't tried this example myself but I think the problem you are having is due to the view passing along the touch event.

Olivier Wilkinson
  • 2,836
  • 15
  • 17