-1

大家好,我需要将此代码转换为具有 2 个参数的函数,在这种情况下,第一个参数是新闻,第二个参数是aif你可以这样做吗?

-(IBAction)news
{
CFURLRef        soundFileURLRef;
SystemSoundID   soundFileObject;
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();

// Get the URL to the sound file to play
soundFileURLRef  =  CFBundleCopyResourceURL (mainBundle,
                                             CFSTR ("News"),
                                             CFSTR ("aif"),
                                             NULL);

// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

AudioServicesPlaySystemSound (soundFileObject);

return;

}

4

2 回答 2

3

如果 CFSTR 是问题所在,那么解决方案是:

-(void) playNews: (NSString*) news type: (NSString*) type
{
    CFURLRef        soundFileURLRef;
    SystemSoundID   soundFileObject;
    CFBundleRef mainBundle;
    mainBundle = CFBundleGetMainBundle ();

    // Get the URL to the sound file to play
    soundFileURLRef  =  CFBundleCopyResourceURL (mainBundle,
            (CFStringRef)news,
            (CFStringRef)type,
            NULL);

    // Create a system sound object representing the sound file
    AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

    AudioServicesPlaySystemSound (soundFileObject);
}

但是(IBAction)声明在这里没有意义,因为这个方法不能直接从 Interface Builder 中使用。

于 2010-10-04T19:35:26.460 回答
0

如果这是一个类从使用控件的用户那里收到的操作,那么您唯一能做的就是-(IBAction)nameOfAction:(id)sender;. 否则,您需要编写命令以获取所需的两个参数并从IBAction.

于 2010-10-04T19:22:57.630 回答