0

我有一个很长的代码,主要是这个问题,大声笑。我有一个很长的代码,我在其中比较单词,当图像设置到 UIImageview 时我会播放声音。问题是其中 1 个我有 5556 个可以播放的选项,所以我必须输入我得到 5556 次的播放声音代码,这真的会让我的代码变长(如果你问的话,它已经是我)

这是代码

//this is no problem here are only 36 of them. 
if (aChar1 == aChar7){
    [imageview7 setImage:imageview1HG.image];
    [imageviewhidden6 setImage:imageview1H.image];
    {
//soundcode
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, 
                                                 (CFStringRef) @"beep-7", CFSTR ("wav"), NULL);

        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }

}
else if 
    (aChar1 == aChar7 && aChar2 == aChar8 && aChar3 != aChar9 && aChar4 != aChar10 && aChar5 != aChar11 &&  aChar6 != aChar12){
        //for these there are 5556 of these lines and I don't want to put that sound file in all of them any other way to do so? 
        if (aChar1 == aChar9){
            [imageview7 setImage:imageview1HO.image];
        }
        else if (aChar1 == aChar10){
            [imageview7 setImage:imageview1HO.image];
        }
        else if (aChar1 == aChar11){
            [imageview7 setImage:imageview1HO.image];                
        }
        else if (aChar1 == aChar12){
            [imageview7 setImage:imageview1HO.image];
        }
        else {
            [imageview7 setImage:imageview1H.image];}
    }

对于第一个使用 imageview1HG 设置图像视图的地方,这没问题,有 36 个这样的,所以没问题,但是对于具有不同 1HO.image 的设置图像,有 5556 个,所以有一些 1 行代码像上面那样播放声音?

我在代码中添加了注释。

4

0 回答 0