我正在尝试创建弹出式摄像头视图但是我收到此错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController _commonPresentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'
我正在调用我的cameraViewController
- (void) cameraButtonSelected
{
CameraViewController *cameraViewController = [[CameraViewController alloc] init];
cameraViewController.view.frame = CGRectMake(100.0, 100.0, 200.0, 150.0);
[self.view addSubview:cameraViewController.view];
}
这是我试图创建的ViewController viewDidLoad方法
- (void)viewDidLoad
{
[super viewDidLoad];
if(self.view.window!=nil)
[objPopView presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
objPopView = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[objPopView presentPopoverFromRect:CGRectMake(842, 163, 0, 0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
答案 0 :(得分:3)
我看到两个问题。
你这么做太早了。 viewDidLoad
表示您的视图在窗口中不。它只是意味着视图存在。等到viewWillAppear:
或viewDidAppear:
执行此操作。这是视图现在在界面中的标志。您可能必须使用条件才能在第一次执行此操作。
这段代码非常奇怪:
if(self.view.window!=nil)
[objPopView presentPopoverFromRect:self.view.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
您尚未定义objPopView
,如果满足此条件,您将执行弹出窗口的此演示,然后直接进行另一个弹出窗口的演示。