简体   繁体   中英

Trying to create a button in Xcode Objective-C

I am just trying something completely new and simple in Xcode. I was looking a tutorial to create a button that plays music or a sound. All seemed to be okay until preview time. There seems to be an expected identifier issue at IBAction as well as it expected something after (void). But each time I do as the prompt says the prompts multiply. I've tried to do as all of them said but then it was no longer the same function. Any ideas?

#import "ViewController.h"
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>

@interface StrackerViewController : ViewController

//@end

//@implementation StrackerViewController: ViewController

- (IBAction) epic; {

    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @ "epic", CFSTR ("mp3"),NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
                    }

- (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.
}

@end

Your IBAction is not a properly formed function. It needs to be in the form:

-(IBAction) epic:(id)sender {

Once you have done that you should probably delete and remake the link with your storyboard as that is likely to be broken too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM