我相信,因为这是一个静态函数,所以在引用此文件的实例变量时遇到了问题.关于如何使该方法不是静态的,或者使它正确引用按钮的任何想法?谢谢解决方案我知道了.诀窍是将按钮传递给回调函数. //定义回调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 callbackAudioServicesAddSystemSoundCompletion (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 itselfstatic 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时尝试从声音回调函数中隐藏按钮时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 00:51