我有一个很长的代码,主要是那个问题,哈哈。我有一个很长的代码,我将相互比较的单词,当一个图像被设置为UIImageview时播放声音。问题是其中一个我有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内衬代码播放上面的声音?
我在代码中添加了评论。