当我遇到一些错误时,我正在构建一个应用程序。在做了一些研究后,我发现原因是因为我正在使用 2 个文件,彼此#import
之间。我读到解决这个问题的方法是使用前向声明,但我找不到一个很好的例子来说明如何做到这一点。
这就是我所拥有的。
RootViewController.h
#import <UIKit/UIKit.h>
#import "FirstDetailViewController.h"
@protocol SubstitutableDetailViewController
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
@end
@interface RootViewController : UITableViewController <UISplitViewControllerDelegate, FirstDetailViewControllerDelegate>{
UISplitViewController *splitViewController;
UIPopoverController *popoverController;
UIBarButtonItem *rootPopoverButtonItem;
NSMutableArray *logMessages;
}
@property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) UIPopoverController *popoverController;
@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
@end
FirstViewDetailController.h
#import <UIKit/UIKit.h>
#import "RootViewController.h
//test2
@protocol FirstDetailViewControllerDelegate <NSObject>
- (void)addItemViewController:(FirstDetailViewController *)controller didFinishEnteringItem:(NSString *)item;
@end
//end test2
@interface FirstDetailViewController : UIViewController <SubstitutableDetailViewController> {
//for the output
IBOutlet UITextView *outputView;
UIToolbar *navigationBar;
}
@property (nonatomic, retain) IBOutlet UIToolbar *navigationBar;
//test
@property(nonatomic, retain) NSString *message;
//end test
@property (nonatomic, retain) id <FirstDetailViewControllerDelegate> delegate;
@end
我知道我需要替换#import
为@class
,但我是否对这两种情况都这样做?另外,我已经#import "FirstDetailViewController.h"
在 RootViewController.m 文件中,所以我也将其切换到那里吗?
我有点困惑,所以任何帮助将不胜感激!