Ios 分析问题预期标识符或;";

Ios 分析问题预期标识符或;";,ios,objective-c,xcode,uiviewcontroller,Ios,Objective C,Xcode,Uiviewcontroller,我正试图创建一个噪音应用程序,但却被卡住了。我不是一个开发者,只是为了好玩而创建的 问题是,我在ViewController.h中的“@interface ViewController:NSObject:UIViewController”行上遇到一个错误,即“预期标识符或“(”” 代码用于ViewController。h为: @interface ViewController : NSObject :UIViewController { } -(IBAction)sound1; -(IBAc

我正试图创建一个噪音应用程序,但却被卡住了。我不是一个开发者,只是为了好玩而创建的

问题是,我在ViewController.h中的“@interface ViewController:NSObject:UIViewController”行上遇到一个错误,即“预期标识符或“(””

代码用于ViewController。h为:

@interface ViewController : NSObject  :UIViewController {
}

-(IBAction)sound1;
-(IBAction)sound2;
-(IBAction)sound3;
-(IBAction)sound4;
-(IBAction)sound5;
-(IBAction)sound6;

@end
ViewController.m的代码为:

#import "ViewController.h"

@implementation ViewController : NSObject;

-(IBAction)five {
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound1", CFSTR("wav"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}

-(IBAction)cramp {
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound2", CFSTR("wav"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}

-(IBAction)cycling {
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound3", CFSTR("wav"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}

-(IBAction)iLoveBanking {
    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文件

   @interface ViewController :UIViewController

  -(IBAction)sound1;
-(IBAction)sound2;
 -(IBAction)sound3;
-(IBAction)sound4;
-(IBAction)sound5;
  -(IBAction)sound6;
  @end
和.m文件将NSObject替换为UIViewController

    #import "ViewController.h"
      @implementation ViewController : UIViewController;
@界面ViewController:NSObject:UIViewController

    #import "ViewController.h"
      @implementation ViewController : UIViewController;
这是错误的,您不能有多个类。您只能从一个类中创建子类。 由于在.m文件中有一些iAction,我猜您正在将其用作视图控制器,并在.h文件中删除NSObject。
@interface ViewController:UIViewController

在我看来应该是这样的


@implementation ViewController

这段代码迫切需要重构,这将

  • 帮助查找导致问题的原因
  • 使它更容易使用
  • 给你

    #import "ViewController.h"
    
    @implementation ViewController
    
    -(IBAction)five {
        [self playSoundWithName:@"sound1"];
    }
    
    -(IBAction)cramp {
        [self playSoundWithName:@"sound2"];
    }
    
    -(IBAction)cycling {
        [self playSoundWithName:@"sound3"];
    }
    
    -(IBAction)iLoveBanking {
        [self playSoundWithName:@"sound4"];
    }
    
    -(IBAction)sound5 {
        [self playSoundWithName:@"sound5"];
    }
    
    -(IBAction)sound6 {
        [self playSoundWithName:@"sound6"];
    }
    
    - (void)playSoundWithName:(NSString *)name
    {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef)name, CFSTR("wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
    
    @end
    
    另外,你的标题应该是

    @interface ViewController : UIViewController
    
    @end
    

    如果您仅从按钮调用iAction方法,则根本不需要在标题中声明它们。

    您不能从两个类继承;只需使用
    UIViewController

    @interface ViewController : UIViewController 
    

    请记住投票并接受解决您问题的答案。感谢您的帮助,但不幸的是xcode表示存在问题。我想做的是创建一个在按下按钮时播放噪音的音板。您介意为我编写代码吗?在编写代码后,我会将声音文件放入正确的文件夹中。@Fogmeister@HarryTGrahamXcode显示的问题是什么?如果您想让我为您编写它,我可以给您发送一张发票并正确执行。:)谢谢您,那太好了!问题在于“(void)playSoundWithName:(NSString*)name{Cbundleref mainBundle=CbundleGetmainbundle();CFURLRef soundFileURLRef;soundFileURLRef=CFBundleCopyResourceURL(mainBundle,(CFStringRef)name,CFSTR(“wav”),NULL);UInt32 soundID;AudioServicesCreateSystemSoundID(soundFileURLRef,&soundID);AudioServicesPlaySystemSound(soundID);}部分每行都有一个问题。最上面的一行写着“预期的类型”,第二行说“使用未声明的标识符”CFURLRef@Fogmeister@HarryTGraham那么我建议找一本关于播放声音的教程。谢谢。我把它放在哪里?在.m或.h中@trojanfoe@HarryTGraham在头文件(
    .h
    )中。