当我的相机使用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];
我可以看到警报视图有点被触发,因为屏幕变暗但我永远看不到警报视图......
感谢您的帮助!
答案 0 :(得分: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];
答案 1 :(得分:1)
代码示例:
- (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];
}