0
我使用这个技巧来为数字键盘放置一个自定义按钮。按钮没有删除removedFromSuperVire
但是在使用后我不能删除按钮,所以在常规键盘上出现在视图顶部。
这是我如何添加:
- (void)keyboardShow:(NSValue *)v
{
if (isKeyboardNumeric) {
// create custom button
UIButton *doneButton = [[UIButton alloc] init];
//doneButton.buttonType = UIButtonTypeCustom;
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) {
[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
} else {
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
[doneButton addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventTouchUpInside];
doneButton.tag = 99;
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
这我怎么删除它:
- (void)keyboardHide
{
UIView *btn;
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
for (btn in keyboard.subviews) {
if (btn.tag==99) {
[btn removeFromSuperview];
[btn release];
break;
}
}
}
}
[self setupButtons];
}
这两种方法都得到正确调用,并在调试我可以证实,被称为
[btn removeFromSuperview]
但无论如何,该按钮仍然存在。
我试图把代码删除它只是在if (isKeyboardNumeric)
调用之前,但没有。
好的,这是公平的。 我改变方式的用户界面的工作,并删除使用工具栏上,顶部的键盘和使用该视图中的黑客。我把按钮需要在导航窗口中。我希望测试版用户更喜欢它;) – mamcx 2009-07-20 17:12:16