I create a delegate on my view controller, this is my code:
FirstController.h
@protocol FirstControllerDelegate;
@interface FirstController : UIViewController
@property (nonatomic, strong) id< FirstControllerDelegate > delegate;
@end
@protocol FirstControllerDelegate <NSObject>
- (void) delegateMethod:(Testo *)testo;
@end
FirstController.m
@synthesize delegate;
if ([self.delegate respondsToSelector:@selector(delegateMethod:)]) {
NSLog(@"respond ok");
[self.delegate delegateMethod:item];
}
SecondController.h
@interface SecondController : UIViewController < FirstControllerDelegate >
SecondController.m
self.firstController = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.firstController setDelegate:self];
- (void) delegateMethod:(Testo *)testo
{
NSLog(@"%@",testo);
}
The problem is that the delegate does not respond to the selector.
The FirstController
is added as the rootViewController
of UINavigationController
that is added as a childViewController
of SecondController
.
I use this way for delegate other times and I don't have any problem!