我在视图控制器上创建了一个委托,这是我的代码:
@protocol FirstControllerDelegate;
@interface FirstController : UIViewController
@property (nonatomic, strong) id< FirstControllerDelegate > delegate;
@end
@protocol FirstControllerDelegate <NSObject>
- (void) delegateMethod:(Testo *)testo;
@end
@synthesize delegate;
if ([self.delegate respondsToSelector:@selector(delegateMethod:)]) {
NSLog(@"respond ok");
[self.delegate delegateMethod:item];
}
@interface SecondController : UIViewController < FirstControllerDelegate >
self.firstController = [[FirstController alloc] initWithNibName:@"FirstController" bundle:nil];
[self.firstController setDelegate:self];
- (void) delegateMethod:(Testo *)testo
{
NSLog(@"%@",testo);
}
问题是委托不响应选择器。
FirstController
被添加为rootViewController
的{{1}},UINavigationController
被添加为childViewController
SecondController
。
我以其他方式使用这种方式代理,我没有任何问题!
答案 0 :(得分:0)
我唯一的猜测是,您在调用delegate
时实际上未设置[self.delegate respondsToSelector:@selector(delegateMethod:)]
,导致nil
调用返回FALSE
。