我剛開始使用Xcode,我正在和一些朋友一起製作一個簡單的音板應用程序。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」中以綠色返回「line」,出現SIGABRT錯誤?
請給我們一個http://www.sscce.org。否則,我幾乎可以確保沒有人會願意閱讀所有這些。把它分解成更小的片斷。有時候,這甚至可以幫助你自己找到答案。 – Drise 2012-07-14 04:04:45
它應該是#import「ViewController.h」而不是「#import」ViewController.h「'。 – Priyal 2015-08-26 13:57:03