Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My program was running fine, but I changed something and now it has over 48 errors.

I think I know the problem, but I don't know how to fix it. I created a class called mViewBase for all my UIViewControllers to derive from.

I decided to have a navigtion bar at the bottom of all my views, to go to other view controllers called cakes2. So cakes2.h imports mViewBase, and mViewBase import cakes2.h

You must be able to do this in Objective-C. Does anybody have any idea of what I can do?

My mViewBase.h file:

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

@interface mViewBase : UIViewController {
    UIView *mBackground;
    UIView *mBackArrow;
    UITextView *mTitle;
    //    Cakes2 *mCakes;
}

-(void) aSetTitle: (NSString *) NewTitle;
-(IBAction) aBack: (id) tender;
-(IBAction) aHome: (id) sender;
-(IBAction) aCakes: (id) sender;
-(IBAction) aCall: (id) sender;
-(IBAction) aDirections: (id) sender;
@end

My Cakes2.h file:

#import <UIKit/UIKit.h>
#import "Gallery.h"
#import "WebView.h"
#import "mViewBase.h" // Circular reference! But I need it

@interface Cakes2 : mViewBase <UITableViewDelegate, UITableViewDataSource> {
    //    Gallery *mGallery;
    IBOutlet UITableView *mMenu;
    // WebView *mWebView;
}
-(IBAction) aOpenWeb;
@end
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
466 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use a forward declaration in one of your header files to avoid the need to import the other header. For example, in mViewBase.h, you can say:

@class Cakes2;

Now the compiler knows that "Cakes2" refers to a class, and you don't need to import the entire Cakes2.h file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...