0

我在我的视图控制器上创建了一个委托,这是我的代码:

第一控制器.h

@protocol FirstControllerDelegate;

@interface FirstController : UIViewController
@property (nonatomic, strong) id< FirstControllerDelegate > delegate;
@end

@protocol FirstControllerDelegate <NSObject>
- (void) delegateMethod:(Testo *)testo;
@end

第一控制器.m

@synthesize delegate; 

if ([self.delegate respondsToSelector:@selector(delegateMethod:)]) {
  NSLog(@"respond ok");
  [self.delegate delegateMethod:item];
}

第二控制器.h

@interface SecondController : UIViewController < FirstControllerDelegate >

第二控制器.m

self.firstController = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.firstController setDelegate:self];

- (void) delegateMethod:(Testo *)testo
{
    NSLog(@"%@",testo);
}

问题是委托不响应选择器。

FirstController被添加为 的rootViewController被添加UINavigationControllerchildViewControllerSecondController

我用这种方式代表其他时间,我没有任何问题!

4

1 回答 1

0

delegate我唯一的猜测是你在调用时没有实际设置[self.delegate respondsToSelector:@selector(delegateMethod:)],导致nil调用返回FALSE

于 2014-01-23T17:16:54.870 回答