我已经设置了一个按钮并将其添加到视图中。我想向UIKeyboardTypeNumberPad添加一个“完成”按钮。这是我的代码。UIButton如何从UIView中删除?
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// 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];
}
一切都很好,直到我想要删除按钮,例如我有一个类型为NumbersAndPunctuation的Kayboard。
如果我点击按钮,我使用[(UIButton)*sender removeFromSuperview];
来防止内存泄漏。
但是,如何从其他功能中删除按钮?
非常感谢!
其他一些人确实在别的地方问过这个问题,但没有得到答案。我确信你可以帮助:)
访问谢谢, 我已经尝试过,但没有成功。我的整个键盘被删除... 一些其他开发者成功提交了应用程序与额外的按钮:) 希望我的也被接受。 – rdesign 2010-01-13 14:02:30
我用过,但是当我触摸另一个键盘时,“完成”按钮仍然存在 – user1561904 2013-05-07 17:19:31