我正在尝试在数字小键盘上添加一个逗号按钮,该按钮具有上一个,下一个和完成按钮,因此它看起来像这样:
问题是,橙色按钮不响应水龙头。实际上,如果我将它移到“7”按钮上方并轻敲它,则会轻敲7。因此,我的橙色按钮可能会显示在键盘上方,但它会对按钮做出反应,就像它在下方一样。
以下是我的代码的摘要:
-(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];
}
我所知道的是,我不应该做this(这实际上不起作用),所以我该怎么办?
答案 0 :(得分:1)
答案由rmaddy在评论中给出:无需添加自定义逗号作为存在逗号的键盘:UIKeyboardTypeDecimalPad
,或在故事板中:
答案 1 :(得分:1)
UITextField* tf = TEXTFIELDNAME;
tf.keyboardType = UIKeyboardTypeDecimalPad;