-3
该代码假设声音是yes或yes 3播放时单击,但我得到一个错误,然后我开始调试,说rand不能静态分配,但我不能把一个*因为它是一个整数。当我这样做时,出现转换错误。我也尝试在声音之前放置一个*,并解决了错误问题,但是当按钮被点击时它不会播放任何东西。那么我该怎么做?指针循环到整数转换?
#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController()
@end
@implementation
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}//this is where the error breakpoint is that you show me how to make
- (IBAction)Yes {
NSInteger rand = arc4random_uniform(2);
NSString sound = rand == 0 ? @"yes" : @"yes 3";
NSURL *url = [[NSBundle mainBundle] URLForResource:sound withExtension:@"mp3"];
AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer play];
}
@end