使用AudioServicesAddSystemSoundCompletion时尝试从声音回调函数中隐藏按钮时出错 [英] Error when trying to hide a button from a sound callback function when using AudioServicesAddSystemSoundCompletion
问题描述
我正在尝试使用声音回调函数在声音文件完成播放后显示一个按钮.
//定义回调AudioServicesAddSystemSoundCompletion(soundID,NULL,NULL,AudioPlaybackComplete,self.nextButton);
这是回调函数:
静态void AudioPlaybackComplete(SystemSoundID ssID,void * clientData)
{
NSLog(@显示这些织补按钮");AudioServicesRemoveSystemSoundCompletion(ssID);//显示按钮,以便您可以切换到下一个动物[nextButton setHidden:YES];
}
我已将nextButton定义为头文件中的插座,并已正确引用.当 [nextButton setHidden:YES];
尝试执行时,出现以下错误:"错误:'nextButton'未声明(此功能首次使用)
".>
我相信,因为这是一个静态函数,所以在引用此文件的实例变量时遇到了问题.关于如何使该方法不是静态的,或者使它正确引用按钮的任何想法?
谢谢
我知道了.诀窍是将按钮传递给回调函数.
//定义回调AudioServicesAddSystemSoundCompletion(soundID,NULL,NULL,AudioPlaybackComplete,self.nextButton);
然后是回调函数本身
静态void AudioPlaybackComplete(SystemSoundID ssID,void * button){NSLog(@显示那些织补按钮");AudioServicesRemoveSystemSoundCompletion(ssID);//显示按钮,以便您可以切换到下一个动物[button setHidden:NO];}
I'm trying to use a sound callback function to show a button once my sound file completes playing.
//defining the callback
AudioServicesAddSystemSoundCompletion (soundID, NULL, NULL, AudioPlaybackComplete, self.nextButton);
Here's the callback function:
static void AudioPlaybackComplete(SystemSoundID ssID, void *clientData)
{
NSLog(@"Show those darn buttons");
AudioServicesRemoveSystemSoundCompletion (ssID);
//show the buttons so you can switch to the next animal
[nextButton setHidden:YES];
}
I've got nextButton defined as an outlet in the header file and referenced properly. I get the following error when the [nextButton setHidden:YES];
tries to execute: "error: 'nextButton' undeclared (first use in this function)
".
I believe because this is a static function it's having problems referencing the instance variable form this file. Any thoughts on how I can have this method not be static, or have it reference the button properly?
Thanks
Ah I figured it out. The trick was to pass in the button to the callback function.
//defining the callback
AudioServicesAddSystemSoundCompletion (soundID, NULL, NULL, AudioPlaybackComplete, self.nextButton);
And then the callback function itself
static void AudioPlaybackComplete(SystemSoundID ssID, void *button)
{
NSLog(@"Show those darn buttons");
AudioServicesRemoveSystemSoundCompletion (ssID);
//show the buttons so you can switch to the next animal
[button setHidden:NO];
}
这篇关于使用AudioServicesAddSystemSoundCompletion时尝试从声音回调函数中隐藏按钮时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!