I'm trying to trigger an AlertView when开发者_Python百科 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!
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];
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];
}
精彩评论