很抱歉,如果这是一个noob问题,但是我的所有代码都没有错误,我无法弄清楚如何获取按钮我按下来执行所有这些操作。它在界面构建器中正确连接。无论如何,如果你可以帮助我,这就是我所拥有的:
在界面
@interface SuprisedViewController : UIViewController {
IBOutlet UIButton *marsStoryButton;
IBOutlet UIButton *marsStoryHome;
@property (nonatomic, retain) IBOutlet UIButton *marsStoryHome;
@property (nonatomic, retain) IBOutlet UIButton *marsStoryButton;
-(void)marsStoryButtonPressed;
实施中
@implementation SuprisedViewController
@synthesize bolloLogo, scaryAlien, exorcist, image1, image2, marsMan, marsStoryButton, marsStoryHome;
-(void)marsStoryButtonPressed {
marsMan.hidden = NO;
marsStoryHome.hidden = NO;
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"longManScream", CFSTR ("wav"), NULL);
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"spressedScream", CFSTR ("wav"), NULL);
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"torturedGirlScream", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
答案 0 :(得分:1)
将头文件中的方法声明为:
-(IBAction)marsStoryButtonPressed;
而不是(void)。然后在“界面”构建器中,您可以通过按住Ctrl键将按钮绑定到文件的所有者(视图控制器)。