Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iPhone中运行摄像头时使用UIAlertView_Iphone_Uialertview_Avcapturesession - Fatal编程技术网

在iPhone中运行摄像头时使用UIAlertView

在iPhone中运行摄像头时使用UIAlertView,iphone,uialertview,avcapturesession,Iphone,Uialertview,Avcapturesession,当我的相机使用OpenCV检测到人脸时,我试图触发AlertView。我成功地完成了人脸检测,并且可以成功地输出NSLog。但是当我试图用 NSLog(@"Face Detected"); UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" message:@"Do you really want to try again?" delegate:self cancelButtonTitle:@"Ca

当我的相机使用OpenCV检测到人脸时,我试图触发AlertView。我成功地完成了人脸检测,并且可以成功地输出NSLog。但是当我试图用

NSLog(@"Face Detected");
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" message:@"Do you really  want to try again?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];

[alert addButtonWithTitle:@"Yes"];

[alert show];
[alert release];
我可以看到警报视图在屏幕变暗时被触发,但我从来没有看到警报视图出来


谢谢你的帮助

删除
[警报解除]
。您已经在上面调用了
autorelease

此外,您还可以集成
[alert addButtonWithTitle:@“Yes”]

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" 
                                                message:@"Do you really  want to try again?" 
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:@"OK", nil] autorelease];

删除
[警报解除]
。您已经在上面调用了
autorelease

此外,您还可以集成
[alert addButtonWithTitle:@“Yes”]

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" 
                                                message:@"Do you really  want to try again?" 
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:@"OK", nil] autorelease];

你从哪里打过来的?主线程还是次线程? 因为UIKit的东西应该总是在主线程上完成

代码示例:

- (void)opencvFaceDetect
{
  // stuff before
  [self performSelectorOnMainThread: @selector(openAlertView) withObject:nil waitUntilDone:false];
  // stuff after
}
然后

- (void)openAlertView
{
  UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" 
                                                message:@"Do you really  want to try again?" 
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:@"OK", nil] autorelease];
}

你从哪里打过来的?主线程还是次线程? 因为UIKit的东西应该总是在主线程上完成

代码示例:

- (void)opencvFaceDetect
{
  // stuff before
  [self performSelectorOnMainThread: @selector(openAlertView) withObject:nil waitUntilDone:false];
  // stuff after
}
然后

- (void)openAlertView
{
  UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" 
                                                message:@"Do you really  want to try again?" 
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:@"OK", nil] autorelease];
}

我认为内存问题实际上是导致错误的原因。警报视图发布得太早,无法显示。我尝试了fabian789的代码,但它再次显示一个暗淡的屏幕,就像调用了警报视图一样,但没有弹出窗口……我认为内存问题实际上是导致错误的原因。警报视图发布得太早,无法显示。我尝试了fabian789的代码,但它再次显示一个暗淡的屏幕,就像调用了警报视图一样,但没有弹出窗口……我尝试在名为opencvFaceDetect的空白中调用警报视图。我如何才能不从主线程调用警报视图?问题是否在于缓冲帧不断显示在屏幕上,使我看不到警报视图?例如,如果您的opencvFaceDetect方法被不在主线程中的方法调用。可以肯定的是,使用NSObject的方法performSelectorOnMainThread:withObject:waitUntilDone:绘制的帧不会有问题,因为您可以看到变暗效果。但我认为真正的问题是fabian789指出的问题:释放太快。我尝试在名为opencvFaceDetect的空白中调用警报视图。我如何才能不从主线程调用警报视图?问题是否在于缓冲帧不断显示在屏幕上,使我看不到警报视图?例如,如果您的opencvFaceDetect方法被不在主线程中的方法调用。可以肯定的是,使用NSObject的方法performSelectorOnMainThread:withObject:waitUntilDone:绘制的帧不会是问题,因为您可以看到变暗效果。但我认为真正的问题是fabian789指向的问题:释放太早。