Objective C&Cocoa Touch中的循环导入问题

cfi*_*her 5 import cocoa-touch objective-c circular-dependency

我在Cocoa Touch中有一个视图控制器,可以检测设备何时旋转,并在它具有的两个视图控制器的视图之间切换:横向和纵向.

我希望UIViewControllersin in能够以FRRRotatingViewController类似的方式访问它,因为所有人都UIViewControllers可以访问UINavigationController它们.

所以我创建了一个具有属性的UIViewController子类(FRRViewController)rotatingViewController.

我也修改了FRRRotatingViewController,所以它需要FRRViewControllers而不是简单UIViewControllers.

不幸的是,当我包括FRRRotatingViewController.hFRRViewController.h(反之亦然),我似乎进入一个圆形的进口问题.我不知道如何解决它.有什么建议?

这是代码:

//
//  FRRViewController.h

#import <UIKit/UIKit.h>
#import "FRRRotatingViewController.h"

@interface FRRViewController : UIViewController

@end

//
//  FRRRotatingViewController.h

#import <UIKit/UIKit.h>
#import "FRRViewController.h"

@class FRRRotatingViewController;


@protocol FRRRotatingViewControllerDelegate

-(void) FRRRotatingViewControllerWillSwitchToLandscapeView: (FRRRotatingViewController *) sender;
-(void) FRRRotatingViewControllerWillSwitchToPortraitView: (FRRRotatingViewController *) sender;

@end


@interface FRRRotatingViewController : FRRViewController {
    // This is where I get the error:Cannot find interface declaration for
    // 'FRRViewController', superclass of 'FRRRotatingViewController'; did you 
    // mean 'UIViewController'?
}

@property (strong) UIViewController *landscapeViewController;
@property (strong) UIViewController *portraitViewController;

@property (unsafe_unretained) id<FRRRotatingViewControllerDelegate> delegate;

-(FRRRotatingViewController *) initWithLandscapeViewController: (UIViewController *) landscape andPortraitViewController: (UIViewController *) portrait;
-(void) deviceDidRotate: (NSNotification *) aNotification;

@end
Run Code Online (Sandbox Code Playgroud)

jba*_*100 17

在大多数情况下,您可以在标头中使用类和协议的前向声明,以避免循环导入问题,但继承的情况除外.在FRRViewController.h,而不是进口FRRRotatingViewController.h,你能否做出前瞻性声明?

@class FRRRotatingViewController;
Run Code Online (Sandbox Code Playgroud)