进行循环引用导入时出错
我的程序运行良好,但我更改了一些内容,现在它有超过 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 UIViewController
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在一个头文件中使用前向声明,以避免导入另一个头文件。例如,在mViewBase.h中,您可以说:
现在编译器知道“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:
Now the compiler knows that "Cakes2" refers to a class, and you don't need to import the entire Cakes2.h file.
我认为您也许应该考虑使用
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.