Created
November 16, 2012 10:45
-
-
Save ishida/4086344 to your computer and use it in GitHub Desktop.
Objective-C Delegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AViewController.h | |
// | |
@protocol AViewControllerDelegate; | |
@interface AViewController : UIViewController <AViewControllerDelegate> | |
{ | |
id <AViewControllerDelegate> delegate; | |
} | |
@property (nonatomic, retain) id <AViewControllerDelegate> delegate; | |
@end | |
@protocol AViewControllerDelegate <NSObject> | |
@optional | |
//- (void)delegateMethod; | |
@end | |
// | |
// AViewController.m | |
// | |
@implementation AViewController | |
@synthesize delegate; | |
- (void)aMethod | |
{ | |
if (delegate && [delegate respondsToSelector:@selector(delegateMethod)]) | |
{ | |
[delegate delegateMethod]; | |
} | |
} | |
@end | |
// | |
// BViewController.h | |
// | |
#import "AViewController.h" | |
@interface BViewController : UIViewController <AViewControllerDelegate> { } | |
@end | |
// | |
// BViewController.m | |
// | |
@implementation BViewController | |
- (void)delegateMethod | |
{ | |
// process | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment