我有两个控制器。一个BaseViewController和MyController。在BaseViewController我有物业,有一个协议iOS协议 - 委托始终为零
BaseViewController.h
@property (nonatomic, strong) MyListener *myListener;
MyListener.h
@protocol MyListenerProtocol;
@interface MyListener : NSObject
@property (nonatomic, weak) id<MyListenerProtocol> delegate;
@end
@protocol MyListenerProtocol;
@protocol MyListenerProtocol <NSObject>
@optional
-(void) myMethod: (int) input;
@end
延伸myController的BaseViewController
@interface MyController : BaseViewController <MyListener>
,并在它的viewDidLoad一个NSObject :
super.myListener = [[MyListener alloc] init];
super.myListener.delegate = self;
在BaseViewController的方法,调用时它的作用:
if (self.myListener && [self.myListener.delegate respondsToSelector:@selector(myMethod:)]) {
[self.myListener.delegate myMethod: input];
}
但在这一点上, “self.myListener” 始终是零。
我想要的是在调用BaseViewController的方法时调用子视图控制器中的方法(但仅适用于某些子视图控制器,而不是全部)。
有什么建议吗?
你确定它是相同的'MyListener'实例吗? – rmaddy
为什么“超级”而不是“自我”? – vikingosegundo
@vikingosegundo我用两种测试,“超级”是我最后的尝试。没有运气。 – Panos