我有一个简单的委托测试,但由于某种原因它没有被调用。
我想通过delegate-(void)test
从AppDelegate
课堂上打电话。
/// AppDelegate.h
#import <Cocoa/Cocoa.h>
@protocol AppDelegateDelegate
@required
-(void)test;
@end
@interface AppDelegate : NSObject <NSApplicationDelegate> {
id<AppDelegateDelegate> _delegate;
}
@property(nonatomic, retain) id<AppDelegateDelegate> delegate;
@end
/// AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize delegate = _delegate;
-(void)awakeFromNib {
[_delegate test];
}
@end
/// 测试.h
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
@interface test : NSObject <AppDelegateDelegate>
-(void)test;
@end
/// 测试.m
#import "test.h"
@implementation test
-(void)test {
//this should be called from AppDelegate
NSLog(@"delegate test");
}
@end