Xcode 的问题!预期的 ”;” 方法原型之后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11480920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trouble with Xcode! Expected ";" after method prototype
提问by Jon Mihail
I'm just starting out with Xcode and I am making a simple soundboard app with some of my friends.
我刚刚开始使用 Xcode,我正在和我的一些朋友一起制作一个简单的音板应用程序。
I am having issues with the first line. I have written the code and I am pretty sure it is correct, but I cannot understand why this is here! I am getting an "Expected ';' after method prototype" and have tried everything to fix it, just inserting the semicolon gives me 3 more errors. here is my code
我的第一行有问题。我已经编写了代码,我很确定它是正确的,但我不明白为什么会在这里!我得到一个“预期的';' 在方法原型之后”并尝试了所有方法来修复它,只是插入分号会给我另外 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
Hey all errors are gone now but when it is run, when i click on a button, it closes and takes me here
嘿,现在所有错误都消失了,但是当它运行时,当我单击一个按钮时,它会关闭并将我带到这里
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
it highlights the "return" line in "main.m" in green with a SIGABRT error?
它以绿色突出显示“main.m”中的“return”行,并带有 SIGABRT 错误?
回答by Caleb
I am having issues with the first line
我的第一行有问题
Of course you are -- you've got complete functions in your interface section. The interface should include method prototypes only. Method definitions go in the implementation section. You have:
当然,您是——您的界面部分拥有完整的功能。接口应该只包含方法原型。方法定义在实现部分。你有:
@interface ViewController ()
- (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];
}
That should instead be:
那应该是:
@interface ViewController ()
- (IBAction)playsound1;
// ...
@end
Followed by:
其次是:
@implementation ViewController
- (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];
}
// ...
@end
(I added some indentation for easier reading.)
(为了便于阅读,我添加了一些缩进。)
回答by Prasad G
You shouldn't write the definition of method in @interface ... @end
. You can declare only methods. Write your method's definition in @implementation ....@end
and declare your methods in @interfaece...@end
.
你不应该在@interface ... @end
. 您只能声明方法。将您的方法定义写入@implementation ....@end
并在@interfaece...@end
.
I think it will be helpful to you.
我想它会对你有所帮助。