0

当我的相机使用 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];

我可以看到警报视图在屏幕变暗时被触发,但我永远看不到警报视图出现...

感谢您的帮助!

4

2 回答 2

3

删除[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];
于 2011-06-23T07:49:18.173 回答
1

你在哪里打电话?主线程还是辅助线程?因为 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];
}
于 2011-06-23T07:51:50.620 回答