Here is my code
classA.h
#import classB.h
@interface classA : UIViewController
{
classB *classb;
}
@property (nonatimic, retain) classB *classb;
@end
classA.m
@implementation classA
@synthesize classb = _classb;
-(void)someMethod
{
self.classb = [[classb alloc]initWithNibName:@"classb" bundle:nil];
[self.view.superview addSubview:self.classb.view];
[self.view removeFromSuperview];
}
@end
That code work well. classb view is loaded normally. The problem starts here
classB.h
#import classA.h
@interface classB: UIViewController
{
classA *classa;
}
@property (nonatimic, retain) classA *classa;
@end
Now in classA I get error
Unknown type name classB;
I think the problem is some kind of recursion.
The idea is classA to load classB view and in some point classB to remove self from superview and add classA as view
move the
#import classA.hfromclassB.htoclassB.mand add@class classAto the header file of classBIf you use a class only in an
@interface(i.e. you don’t use a@protocoldefined in that class header) it’s enough to use the@class SomeClassstatement.This will prevent circular includes.
classB.h:
classB.m: