Actually I have three view controllers named in my app. I am navigating from A to B and then B to C. I am calling delegate method from C which is implemented in A. here is my code for
A.h
#import "A.h"
#import "C.h"
In A.m
I have
@interface A()<delegateName>
-(void)delegateMethod
{
NSLog(@"delegate");
}
-(void)moveToB
{
C *instanceOfC=[C alloc] init];
instanceOfC.delegate=self; //line 1
}
In B.h
#"import C.h"
In B.m
-(void)moveToC
{
A *instanceOfA=[[A alloc] init];
C *instanceOfC=[[C alloc] init];
instanceOfC.delegate= instanceOfA; //line 2
}
In C.h
@protocal delegateName <NSObject>
-(void)delegateMethod;
@end
@interface C
@property(nonatomic,weak) id<delegateName> delegate;
@end
In C.m
@synthesize delegate;
-(void)inSomeMethod
{
[delegate delegateMethod];
}
if I put <delegateName>
in A.h
instead of A.m
then it says undeclared delegate
.