0

我在编写应用程序时遇到了一些麻烦,当我尝试运行时,它会出错,导致实现不完整。

这是 ViewController.m 的代码 - 你能告诉我我做错了什么吗?

我还将在 .m 的代码下方包含 ViewController.h 的代码

视图控制器.m

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController

 -(IBAction)infoButtonpressed:(id)sender;
 {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];

second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:second animated:YES];

}

-(IBAction)sound1 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound1", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

-(IBAction)sound2 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound2", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

-(IBAction)sound3 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound3", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

-(IBAction)sound4 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound4", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

-(IBAction)sound5 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound5", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

-(IBAction)sound6 {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound6", CFSTR("wav"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

@end

视图控制器.h

#import <AudioToolbox/AudioToolbox.h>

@interface ViewController :UIViewController {

}

-(IBAction)switchviews;

-(IBAction)sound1;

-(IBAction)sound2;

-(IBAction)sound3;

-(IBAction)sound4;

-(IBAction)sound5;

-(IBAction)sound6;

-(IBAction)infoButtonpressed:(id)sender;

@end
4

2 回答 2

2
-(IBAction)switchviews;

在头文件中声明,但从未在实现 ( .m) 文件中实现。

于 2012-09-22T09:16:01.643 回答
0

@H2CO3 - 是对的

在您的应用程序-(IBAction)switchviews;中声明在.h文件中,但未在文件中声明.m。所以首先你需要声明 -(IBAction)switchviews; .m带有相关代码的文件中的方法。

于 2012-09-22T09:24:47.923 回答