开发者

Why do I get this error "error: expected specifier-qualifier-list before MyTableViewController

开发者 https://www.devze.com 2023-01-20 07:18 出处:网络
1) I have the CoreData.framework imported. In Groups & Files I see it in the Framworks list together with UIKit.framework, Foundation.framework, CoreGraphics.framework.

1) I have the CoreData.framework imported. In Groups & Files I see it in the Framworks list together with UIKit.framework, Foundation.framework, CoreGraphics.framework.

2) I have this code, I am not sure what this error means

#import <UIKit/UIKit.h>

@interface SQLLiteDemoAppDelegate : NSObject <UIApplicationDelegate> {
   UIWindow *wi开发者_开发技巧ndow;
   MyTableViewController *myTableViewController; //error on this line
}

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

@end

MyTableViewController.h looks like this
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>


@interface MyTableViewController : UITableViewController {
NSMutableArray *names;
}

@end


MyTableViewController is not declared where you're using it so compiler can't know how to treat that name. You have 2 options how to fix that:

  1. just import the MyTableViewController.h in your SQLLiteDemoAppDelegate.h file
  2. use forward declaration in your header class and import SQLLiteDemoAppDelegate.h in .m file:

    //SQLLiteDemoAppDelegate.h
    @class MyTableViewController;
    @interface SQLLiteDemoAppDelegate : NSObject <UIApplicationDelegate> {
    ...
    
    
    //SQLLiteDemoAppDelegate.m
    #import "MyTableViewController.h"
    ...
    


Have a look at

http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/ObjectiveC/Articles/ocDefiningClasses.html

the part about "Referring to Other Classes".

If the interface mentions classes not in this hierarchy, it must import them explicitly or declare them with the @class directive

In your case that would mean you have to insert

@class MyTableViewController;

before the declaration of the interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消