我想从myRenderer
将一组对象发送回myViewController在myRenderer.h中:
@protocol myProtocol;
@interface myRenderer : NSObject
@property (weak) id <myProtocol> myDelegate;
@end
@protocol myProtocol <NSObject>
- (void)sendToMyViewController : (NSMutableArray *) objects;
@end
在myRenderer.mm(C ++ / objective-c代码)中:
@implementation myRenderer
@synthesize myDelegate;
.
.
.
-(void) sendObjects
{
[myDelegate sendToMyViewController : objects];
Problem:
myDelegate is always <nil>; = (id) 0x0
}
.
.
.
@end
在myViewController.h中:
@interface myViewController : UIViewController <myProtocol>
.
.
.
@end
myViewController.m中的:
@implementation myViewController
.
.
.
- (void)viewDidLoad
{
renderer = [[MyRenderer alloc] init];
renderer.myDelegate = self;
}
.
.
.
-(void) sendToMyViewController : (NSMutableArray *) objects
{
// do something with objects
Problem:
this method is never called !!!
}
.
.
.
@end
问题: myDelegate总是零;等于(id)0x0和 sendToMyViewController从未调用过。
感谢您的帮助。
答案 0 :(得分:0)
解决!
@CRD谢谢你的提示!
确实存在多个MyRender实例,将它们缩减为单个实例解决了问题。