我刚开始使用 Xcode,我正在和一些朋友一起制作一个简单的音板应用程序。
我在第一行遇到问题。我已经编写了代码,我很确定它是正确的,但我不明白为什么会在这里!我得到一个“预期的';' 在方法原型之后”并尝试了一切来修复它,只需插入分号就会给我带来 3 个更多错误。这是我的代码
'#import "ViewController.h"'
@interface ViewController ()
// Sound for Ben
- (IBAction)playsound1 { // this is where the error is. It is not on any other line
NSString *path = [[NSBundle mainBundle] pathForResource:@"Ben" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Bruno
- (IBAction)playsound2 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Bruno" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Homer
- (IBAction)playsound3 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Homer" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Jon
- (IBAction)playsound4 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Jon" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Mark
- (IBAction)playsound5 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Mark" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Mikey
- (IBAction)playsound6 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Mikey" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Omar
- (IBAction)playsound7 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Omar" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Tom
- (IBAction)playsound8 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Tom" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
// Sound for Victor
- (IBAction)playsound9 {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Victor" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
嘿,现在所有错误都消失了,但是当它运行时,当我单击一个按钮时,它会关闭并带我到这里
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
它以绿色突出显示“main.m”中的“return”行并带有 SIGABRT 错误?