您可以创建自己的:
在 MyView1.h 中:
@class MyView1;
@protocol MyView1Delegate <NSObject>
- (void)closeMyView1:(MyView1 *)myView1;
@end
@interface MyView1 : NSObject
{
id<MyView1Delegate> _delegate;
}
@property (assign, nonatomic, readwrite) id<MyView1Delegate> delegate;
...
@end
在 MyView1.m 中:
@interface MyView1
@synthesize delegate = _delegate;
...
// The method that tells the delegate to close me
- (void)closeMe
{
....
if ([_delegate respondsToSelector:@selector(closeMyView1:)])
{
[_delegate closeMyView1:self];
}
}
@end
在 AppDelegate.h 中:
#import "MyView1.h"
@interface AppDelegate <MyView1Delegate>
{
MyView1 *_myView1;
}
...
@end
在 AppDelegate.m 中:
- (void)someCreateViewMethod
{
_myView1 = [[MyView1 alloc] initWithFrame:NSMakeRect(0, 0, 100, 200)];
[_myView1 setDelegate:self];
...
}