我遇到了一个奇怪的问题,试图调用我的委托 - 它永远不会被调用。据我所知,委托永远不会被设置。我正在使用ARC。
CueCreateDelegate.h
#import <Foundation/Foundation.h>
@class CueCreateDelegate;
@protocol CueCreDelegate <NSObject>
- (void)CueCreatedCall;
@end
@interface CueCreateDelegate : NSObject
@property (nonatomic, assign) id <CueCreDelegate> delegate;
-(void)CueCreated;
- (void) setdelegate:(id<CueCreDelegate>) delegates; //for testing
@end
CueCreateDelegate.m 从另一个类调用CueCreated并打印坏消息......
#import "CueCreateDelegate.h"
@implementation CueCreateDelegate
@synthesize delegate ;
- (void) setdelegate:(id<CueCreDelegate>) delegates{
delegate = delegates;
}
-(void)CueCreated{
if ([delegate respondsToSelector:@selector(CueCreatedCall)]) {
[delegate CueCreatedCall];
}
else{
NSLog(@"Delegate method not getting called...%@",delegate);
}
}
@end
MatrixViewController.h
#import <UIKit/UIKit.h>
#import "CueCreateDelegate.h"
@interface MatrixViewController : UIViewController<UIGestureRecognizerDelegate,CueCreDelegate>{
CueCreateDelegate *cueCre;
}
MatrixViewController.m 永远不会调用CueCreatedCall ..
-(void)CueCreatedCall{
NSLog(@"lsakdlakjdlks");
}
- (void)viewDidLoad
{
cueCre = [[CueCreateDelegate alloc] init];
// [cueCre setdelegate:self];
[cueCre setDelegate:self];
NSLog(@"%@",[cueCre delegate]);
}