UItextField の編集が開始されて popover を表示する必要があるときに、誰かが私を助けることができますか?
このプログラミングは初めてです
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self showPopOverController];
}
- (void)showPopOverController
{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_popover = [[UIPopoverController alloc] initWithContentViewController:self.imgPicker];
[_popover setDelegate:self];
[_popover presentPopoverFromRect:self.txtField.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
.h ファイルで宣言する必要がある場所
UIPopoverController *_popover;
@property (strong, nonatomic) IBOutlet UITextField *txtField;
@property (nonatomic, retain) UIImagePickerController *imgPicker;
これはiPadでのみ機能します
テキストフィールドのデリゲートメソッドの1つを使用して、テキストフィールドの編集が開始されるとすぐにポップオーバーを表示できます
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self showPopOver];
}
注:- showPoperOver はカスタム メソッドです。
また
通知用のオブザーバーに通知できます
UITextFieldTextDidBeginEditingNotification
UITextField
デリゲートを自分自身に設定するがあることを確認してください。
[textField setDelegate : self];
次に、デリゲートを使用します
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
// call the method where u r making ur popover
}
このデリゲートは、 で書き込みを開始すると呼び出されますUITextField
。