Я установил кнопку и добавил ее в представление. Я хочу добавить кнопку «Готово» в UIKeyboardTypeNumberPad. Вот мой код.
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];
}
Все прекрасно работает, пока я не хочу удалить кнопку, если у меня есть Kayboard типа NumbersAndPunctuation, например.
Если я нажму на кнопку, я использую [(UIButton)*sender removeFromSuperview];
для предотвращения утечек памяти.
Но как мне удалить кнопку из другой функции?
Большое спасибо!
Некоторые другие парни задавали этот вопрос где-то еще, но не получили ответа. Я уверен, что вы можете помочь:)