numberkeyboard를 사용 중이며 bottem 왼쪽 구석에 완료 키를 추가하고 있습니다. 키보드에서이 버튼을 제거하고 싶습니다. 나중에 일반 키보드를 사용하기 때문에 완료 버튼이 계속 표시됩니다. 전 세계적으로 UIButton을 선언하고 그것에 removeFromSuperview를 호출하고 있습니다. 아무 반응이 없습니다. 또한 removeFromSuperview 메서드를 추가 할 때 removeFromSuperview 메서드를 호출하면 성공적으로 단추가 제거됩니다. 여기에 몇 가지 코드가 있습니다.키보드에서 UIButton을 제거 할 수 없습니다.
-(void)addHideKeyboardButtonToKeyboard{
// Locate non-UIWindow.
keyboardWindow=nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
if (!keyboardWindow) return;
// Locate UIKeyboard.
UIView *foundKeyboard = nil;
for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
}
if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
foundKeyboard = possibleKeyboard;
break;
}
}
if (foundKeyboard) {
// create custom button
NSString *deviceType = [UIDevice currentDevice].model;
if(!([deviceType isEqualToString:@"iPad"] || [deviceType isEqualToString:@"iPad Simulator" ]))
{
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(textFieldShouldReturn:) forControlEvents:UIControlEventTouchUpInside];
[foundKeyboard addSubview:doneButton];
}
}
}
과 doneButton을 제거하는
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[doneButton removeFromSuperView];
}
doneButton 포인터를 nil로 설정했지만 아직 키보드보기에 추가되어 있기 때문에 이는 작동하지 않습니다. – James