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

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

问题描述

我的程序运行良好,但我更改了一些东西,现在它有超过 48 个错误.

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

我想我知道问题所在,但我不知道如何解决.我创建了一个名为 mViewBase 的类,用于我所有的 UIViewController 派生.

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 的其他视图控制器.所以 cakes2.h 导入了 mViewBase,而 mViewBase 导入 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

我的 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天全站免登陆