我已經設置了一個按鈕並將其添加到視圖中。我想向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