0

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!

staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
francesco.venica
  • 1,703
  • 2
  • 19
  • 54

1 Answers1

0

My only guess is that you haven't actually set delegate when calling [self.delegate respondsToSelector:@selector(delegateMethod:)], result in in a nil call which returns FALSE.

Stefan Fisk
  • 1,563
  • 13
  • 19
  • I find the error, that is a stupid error, from this controller I push another controller of the same type, when I push the new control I don't set the delegate, I set it on th first controller but not into the second, now it work! – francesco.venica Jan 23 '14 at 18:08