아래의 편리한 코드를 사용하여 숫자 버튼에 완료 버튼을 추가했습니다. 하지만 MFMailComposeViewController를 시작하는 전자 메일 단추가 있습니다. 완료 버튼이 전자 메일 키보드에 나타나지 않는 것을 어떻게 확인합니까?iPhone의 숫자 패드 키보드에만 완료 버튼 추가
//
// UIViewController+NumPadReturn.m
// iGenerateRandomNumbers
//
// Created by on 12/4/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "UIViewController+NumPadReturn.h"
@implementation UIViewController (NumPadReturn)
-(void) viewDidLoad{
// add observer for the respective notifications (depending on the os version)
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
}
}
- (void)keyboardWillShow:(NSNotification *)note {
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
[self addButtonToKeyboard];
}
}
- (void)keyboardDidShow:(NSNotification *)note {
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[self addButtonToKeyboard];
}
}
- (void)addButtonToKeyboard {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
[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(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 found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
- (void)doneButton:(id)sender {
NSLog(@"doneButton");
[self.view endEditing:TRUE];
}
@end
이 하위 클래스를 가져올 때 자동으로 UIViewController를 확장하려고하므로 내 응용 프로그램의 부울 플래그가 작동하지 않을 수 있습니다.
샘플 코드로 자세히 설명 할 수 있습니까? inputAccessoryView는 어디에 사용합니까? – Bryan
문서에서'inputAccessoryView'를 찾는다. myTextField.inputAccessoryView = ...'에 커스텀 뷰를 지정하면,이 텍스트 필드가 최초의 응답자가되었을 때에 자동적으로 표시됩니다. –
버튼을 배치 할 수 없습니다. 그것은 키보드의 상단과 중앙에 머물 렀지 만 작동합니다. – Bryan