我有一个奇怪的问题,试图打电话给我的代表 - 它永远不会被调用。据我了解,代表永远不会被设置。我正在使用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
矩阵视图控制器.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]);
}