-1

みなさん、こんにちは。このコードを2つのパラメーターを持つ関数に変換する必要があります。この場合、最初のパラメーターはNewsで、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);
}

ただし、このメソッドはInterface Builderから直接使用できないため、 (IBAction)宣言はここでは意味がありません。

于 2010-10-04T19:35:26.460 に答える
0

これが、コントロールを使用してユーザーからクラスによって受信されるアクションであることが意図されている場合、実行できるのは。だけです-(IBAction)nameOfAction:(id)sender;。それ以外の場合は、必要な2つの引数を取り、それをから呼び出すコマンドを作成する必要がありますIBAction

于 2010-10-04T19:22:57.630 に答える