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 に答える