当相机在 iPhone 中运行时使用 UIAlertView

发布于 2024-11-16 22:15:32 字数 463 浏览 2 评论 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];

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

感谢您的帮助!

I'm trying to trigger an AlertView when my camera detect a face using OpenCV. I manage to do the face detection and can output an NSLog successfully. But when I tried to trigger the alert view with

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];

I can see the Alert View is kind of triggered as the screen is dimmed but I could never see the alert view came out...

Thanks for helping!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此刻的回忆 2024-11-23 22:15:32

删除[警报发布]。您已经对其调用了 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];

Remove [alert release]. You already called autorelease on it.

Also, you can integrate [alert addButtonWithTitle:@"Yes"]; in the initializer:

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Face Detected" 
                                                message:@"Do you really  want to try again?" 
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                      otherButtonTitles:@"OK", nil] autorelease];
如梦初醒的夏天 2024-11-23 22:15:32

你从哪里打电话来的?主线程还是次要线程?
因为 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];
}

where are you calling this from ? Main thread or secondary ?
Because UIKit stuff should always been done on main thread.

Code example:

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

and then

- (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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文