Objective C number keypad, custom comma button

Posted by rom_j on Stack Overflow See other posts from Stack Overflow or by rom_j
Published on 2014-06-12T03:20:21Z Indexed on 2014/06/12 3:24 UTC
Read the original article Hit count: 209

Filed under:
|
|

I'm trying to add a comma button on a number keypad that has previous, next and done buttons, so that it looks like this :

Orange button is the one I'm trying to make work

Problem is, that the orange button does not respond to taps. Actually if I moved it above the "7" button and tapped it, the 7 would be tapped. So my orange button may be shown above the keyboard, but it's reacting to taps as if it were below.

Here is an abstract of my code :

 -(void)textFieldDidBeginEditing:(UITextField *)textField{
   UIView *inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 500, screenWidth, 40.0)];
   // 3 buttons on top
   UIView *topToolbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0.0, screenWidth, 40.0)];
   [topToolbar addSubview:self.inputPrevButton];
   [topToolbar addSubview:self.inputNextButton];
   [topToolbar addSubview:self.inputDoneButton];
   [inputAccessoryView addSubview:topToolbar];
   // Comma button
   UIButton *commaButton = [UIButton buttonWithType:UIButtonTypeCustom];
   [commaButton setFrame: CGRectMake(0, 204, 105, 52)];
   [commaButton setTitle:@"." forState:UIControlStateNormal];
   [commaButton addTarget:self action:@selector(addComma) forControlEvents:UIControlEventTouchUpInside];
   [commaButton setBackgroundColor:[UIColor orangeColor]];

   [inputAccessoryView addSubview:commaButton];
   // Useless, but tried anyway
   [inputAccessoryView bringSubviewToFront:commaButton];

   [textField setInputAccessoryView:self.inputAccessoryView];
 }

All I know is that I should not be doing this (which is actually not working), so what should I do ?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c