开发者

Xcode: very strange error subclassing my own class

I have an iPhone app with a custom class, Detail, a subclass of UIViewController that I created.

I need to make a subclass of Detail, and I want to to call it Acti开发者_如何学CvityDetail. So I wrote the following in my ActivityDetail.h file:

#import <UIKit/UIKit.h>
#import "Detail.h"

@interface ActivityDetail : Detail {

}

@end

The problem is that I'm getting a compiler error telling me this:

error: cannot find interface declaration for 'Detail', superclass of 'ActivityDetail'

And the strange thing is: I can change the superclass from Detail to UIView (for example), compile getting many errors (obviously), and then change the superclass to Detail again and everything works fine! But if I then change anything to the Detail class the problem comes back from the beginning...

How can I solve this?


It is recommended to not import classes beyond the default Foundation or UIKit imports in your header files. Instead you should do something similar:

Header

#import <UIKit/UIKit.h>

@class Detail;

@interface ActivityDetail : Detail {

}

@end

Implementation

#import "ActivityDetail.h"
#import "Detail.h"

@implementation ActivityDetail

@end

This allows your header to "know" about additional classes without forcing all "importers" of that header to also import everything it imports.


Here is a great reference question, and a great answer, regarding the usage of @class and #import.


Erm you are importing Detail as Dettaglio.h. Probably the compiler is not fluent in Italian.


Are you importing the .h where Detail is declared?

  #import "Detail.h"


Either #import "Detail.h" or subclass from Dettaglio (depends on whichever one your Detail class is actually named.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜