我已经创建了一个UIImagePickerController的简单子类,如下所示:
@interface CustomImagePicker : UIImagePickerController <UITextViewDelegate> {
}
-(void) viewDidAppear:(BOOL)animated{
// make sure to call the same method on the super class!!!
//
[super viewDidAppear:animated];
UITextView *textView = [[[UITextView alloc] init] autorelease];
[self.view addSubview:textView];
[textView becomeFirstResponder];
[textView setDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyPressed:) name: UITextViewTextDidChangeNotification object: nil];
}
- (void)textViewDidChange:(UITextView *)textView{
NSLog(@"Picture Taken 2");
[self takePicture];
}
-(void) keyPressed: (NSNotification*) notification
{
NSLog(@"Picture Taken 1");
[self takePicture];
}
在我的主窗口中,我以模态方式打开它:
camera = [[CustomImagePicker alloc] init];
camera.delegate = self;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.allowsEditing = NO;
camera.showsCameraControls = NO;
camera.wantsFullScreenLayout = NO;
//camera.cameraOverlayView = myView;
[self presentModalViewController:camera animated:YES];
按键或textviewDidChange都没有被调用。
任何人都有这方面的经验吗?
提前致谢!
答案 0 :(得分:2)
我认为你不能继承UIImagePickerController的子类。
以下文件 - http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html 指定 “重要:UIImagePickerController类仅支持纵向模式。此类旨在按原样使用,不支持子类化。”
答案 1 :(得分:0)
我相信它应该有用。需要一些详细信息。
换句话说,尝试使用UITextViewDelegate
UITextView *textView = [[[UITextView alloc] init] autorelease];
[self.view addSubview:textView];
[textView becomeFirstResponder];
[textView setDelegate:self];
并实施;你班上的- (void)textViewDidChange:(UITextView *)textView;
方法。