2

我已经在我的项目中实现了 textToSpeech 并希望在说出文本时显示警报视图。这里我调用 textToSpeech 的方法:

//-----before TTS starts i try to display alertView with Cancelbutton  
//[self performSelectorOnMainThread:@selector(alertWhileTTS) withObject:nil waitUntilDone:YES]; //gray view and no alertview
//[self performSelector:@selector(alertWhileTTS)];  //gray view and no alertview
//[self alertWhileTTS];  //gray view and no alertview

//this part here is blocking, no gray screen, 
//after TTS is ready, the alertView is displayed
dispatch_async(dispatch_get_main_queue(), ^{
        //Update UI if you have to
        [self alertWhileTTS];
    });


[[self view] setNeedsDisplay];
[self synthesizeInBackground];
[queue waitUntilAllOperationsAreFinished];
[self setIsSpeaking: false];
[[self view] setNeedsDisplay];  

这里的 synthesizeInBackground 方法(in 方法 synthesize 启动 TTS):

- (void) synthesizeInBackground {
    queue = [[NSOperationQueue alloc] init];
    operation = [[NSInvocationOperation alloc] initWithTarget:self 
    selector:@selector(synthesize) object:nil];

    [queue addOperation: operation];
}  

虽然 TTS 我想显示一个带有cancel按钮的 alertView。但在我的情况下,我只得到一个没有 alertView 的灰屏。

如何正确调用 alertWhileTTS,以便显示 alertView?

这里是 alertWhileTTS 的内容:

- (void) alertWhileTTS {
UIAlertView *inboxRead = [[[UIAlertView alloc] initWithTitle:@"Inbox tts..."
                                                    message:nil
                                                   delegate:self
                                          cancelButtonTitle:@"Abbrechen"
                                          otherButtonTitles:nil] autorelease];
inboxRead.tag = 997;

[inboxRead show];
}  

更新查看我的解决方案,该解决方案有效:

[self performSelectorOnMainThread:@selector(alertWhileTTS) withObject:nil waitUntilDone:YES];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
        [[self view] setNeedsDisplay];
        [self synthesizeInBackground];
        [queue waitUntilAllOperationsAreFinished];
        [self setIsSpeaking: false];
        [[self view] setNeedsDisplay];

    }); 
4

2 回答 2

1

您应该使用自动引用计数 (ARC),因为它会自动释放所有内容。正如 borrden 所说,您(大概)正在快速发布 UIAlertView。

于 2012-06-05T14:44:19.693 回答
1

更改 alertWithTTsTo

UIAlertView *inboxRead = [[[UIAlertView alloc] initWithTitle:@"Inbox tts..."
                                                    message:nil
                                                   delegate:self
                                          cancelButtonTitle:@"Abbrechen"
                                          otherButtonTitles:nil] autoRelease];
inboxRead.tag = 997;

[inboxRead show];

alertWhileTTS也不要忘记从主ui线程调用函数通过做

 dispatch_async(dispatch_get_main_queue(), ^{
        //Update UI if you have to
        [self alertWhileTTS];
    });
于 2012-06-05T14:47:09.707 回答