【问题标题】:Why do I get this error "error: expected specifier-qualifier-list before MyTableViewController为什么我会收到此错误“错误:MyTableViewController 之前的预期说明符限定符列表
【发布时间】:2010-10-15 15:27:50
【问题描述】:

1) 我导入了 CoreData.framework。在 Groups & Files 中,我在 Framworks 列表中看到它以及 UIKit.framework、Foundation.framework、CoreGraphics.framework。

2) 我有这个代码,我不确定这个错误是什么意思

#import <UIKit/UIKit.h>

@interface SQLLiteDemoAppDelegate : NSObject <UIApplicationDelegate> {
   UIWindow *window;
   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

【问题讨论】:

    标签: core-data ios4 uitableview


    【解决方案1】:

    MyTableViewController 未在您使用它的地方声明,因此编译器无法知道如何处理该名称。你有 2 个选项来解决这个问题:

    1. 只需将 MyTableViewController.h 导入您的 SQLLiteDemoAppDelegate.h 文件中
    2. 在头类中使用前向声明并在 .m 文件中导入 SQLLiteDemoAppDelegate.h:

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

    【讨论】:

      【解决方案2】:

      看看

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

      关于“引用其他类”的部分。

      如果接口提到不在此层次结构中的类,则必须显式导入它们或使用@class 指令声明它们

      在你的情况下,这意味着你必须插入

      @class MyTableViewController;
      

      在接口声明之前。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-06
        • 1970-01-01
        • 2011-09-25
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多