进行循环引用导入时出错

发布于 2024-12-02 04:36:30 字数 1171 浏览 1 评论 0原文

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

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

我决定在所有视图的底部有一个导航栏,以转到名为 cakes2 的其他视图控制器。所以 cakes2.h 导入 mViewBase,并且 mViewBase import cakes2.h

您必须能够在 Objective-C 中执行此操作。有人知道我能做什么吗?

我的 mViewBase.h 文件:

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

#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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里°也失望 2024-12-09 04:36:30

您可以在一个头文件中使用前向声明,以避免导入另一个头文件。例如,在mViewBase.h中,您可以说:

@class Cakes2;

现在编译器知道“Cakes2”引用一个类,并且您不需要导入整个Cakes2.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;

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

婴鹅 2024-12-09 04:36:30

我认为您也许应该考虑使用 UITabBarController。它是专门为从屏幕底部的栏管理多个视图控制器而设计的。

I think you should perhaps consider using a UITabBarController. It is made specifically for managing several view controllers from a bar at the bottom of the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文