簡體   English   中英

錯誤:預期為“;” 在Xcode中的“接口”之前

[英]Error: expected ';' before 'interface' in Xcode

我正在嘗試通過iPhone的Hello World教程運行,但出現此錯誤:錯誤:預期為';' 在“界面”之前,我已經檢查過並且我的文件與教程相同(空格除外),而且我不知道為什么會有這個問題。 如果需要,我可以提供代碼。

HelloWorldAppDelegate.h:

//
//  HelloWorldAppDelegate.h
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MyViewController

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MyViewController *myViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) MyViewController *myViewController;

@end

HelloWorldAppDelegate.m:

//
//  HelloWorldAppDelegate.m
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "MyViewController.h"
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize myViewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    MyViewController *aViewController = [[MyViewController alloc]
                                         initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
    [self setMyViewController:aViewController];
    [aViewController release];
    UIView *controllersView = [myViewController view];
    [window addSubview:controllersView];

    [window makeKeyAndVisible];
}


- (void)dealloc {
    [myViewController release]; 
    [window release];
    [super dealloc];
}


@end

MyViewController.h:

//
//  MyViewController.h
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {

}

@end

MyViewController.m:

//
//  MyViewController.m
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "MyViewController.h"


@implementation MyViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

這是您的問題,在第一行:

@class MyViewController

分號在哪里?

您沒有這個問題,但是當我收到此錯誤時,在產生該錯誤的類的實現文件的開頭有一個備用字母:

G//
//  ManagedObjectAttributeEditor.m
//  App
//
//  Created by Rose Perrone on 7/28/10.
//  Copyright 2010 Company. All rights reserved.
//

#import "ManagedObjectAttributeEditor.h"

@implementation ManagedObjectAttributeEditor

您可能忘記了struct或enum decl或同一文件或包含文件中的內容后的分號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM