进行循环引用时出错 [英] Errors when making circular reference imports

查看:113
本文介绍了进行循环引用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序运行正常,但我改变了一些东西,现在有超过48个错误。

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

我想我知道问题,但我不知道修复它。我为所有的 UIViewController 创建了一个名为 mViewBase 的类。

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.

我决定在我的所有视图的底部有一个导航栏,去其他视图控制器 cakes2 。 so cakes2.h import mViewBase mViewBase import cakes2.h

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

你必须能够在Objective-C中做到这一点。有没有人知道我可以做什么?

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

我的mViewBase.h文件:

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文件:

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


推荐答案

声明在您的一个头文件中,以避免需要导入其他头。例如,在mViewBase.h中,您可以说:

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;

现在编译器知道Cakes2是指一个类,整个Cakes2.h文件。

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

这篇关于进行循环引用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆